#pragma once
#ifndef _INC_MALLOC // include guard for 3rd party interop
#define _INC_MALLOC
#include <corecrt.h>
#include <corecrt_malloc.h>
_CRT_BEGIN_C_HEADER
__pragma
(pack(push,
8
))
extern
"C"
{
#ifdef _WIN64
#define _HEAP_MAXREQ 0xFFFFFFFFFFFFFFE0
#else
#define _HEAP_MAXREQ 0xFFFFFFE0
#endif
#define _HEAPEMPTY (-1)
#define _HEAPOK (-2)
#define _HEAPBADBEGIN (-3)
#define _HEAPBADNODE (-4)
#define _HEAPEND (-5)
#define _HEAPBADPTR (-6)
#define _FREEENTRY 0
#define _USEDENTRY 1
typedef
struct
{
int
*
;
;
int
;
}
;
#define _mm_free(a) _aligned_free(a)
#define _mm_malloc(a, b) _aligned_malloc(a, b)
_Ret_notnull_ _Post_writable_byte_size_(_Size)
void* __cdecl _alloca(_In_ size_t _Size);
#if !defined __midl && !defined RC_INVOKED
_ACRTIMP intptr_t __cdecl _get_heap_handle(void);
__declspec
(dllimport)
__cdecl
(
void
);
_Check_return_
_DCRTIMP int __cdecl _heapmin(void);
__declspec
(dllimport)
int
__cdecl
(
void
);
#if defined _DEBUG || defined _CRT_USE_WINAPI_FAMILY_DESKTOP_APP || defined _CORECRT_BUILD
_ACRTIMP int __cdecl _heapwalk(_Inout_ _HEAPINFO* _EntryInfo);
#endif
__declspec
(dllimport)
int
__cdecl
(
*
);
#ifdef _CRT_USE_WINAPI_FAMILY_DESKTOP_APP
_Check_return_ _DCRTIMP int __cdecl _heapchk(void);
#endif
__declspec
(dllimport)
int
__cdecl
(
void
);
_DCRTIMP int __cdecl _resetstkoflw(void);
__declspec
(dllimport)
int
__cdecl
(
void
);
#define _ALLOCA_S_THRESHOLD 1024
#define _ALLOCA_S_STACK_MARKER 0xCCCC
#define _ALLOCA_S_HEAP_MARKER 0xDDDD
#ifdef _WIN64
#define _ALLOCA_S_MARKER_SIZE 16
#else
#define _ALLOCA_S_MARKER_SIZE 8
#endif
_STATIC_ASSERT(sizeof(unsigned int) <= _ALLOCA_S_MARKER_SIZE);
typedef
char
[(
sizeof
(
unsigned
int
) <=
8
) !=
0
];
#pragma warning(push)
#pragma warning(push)
#pragma warning(disable:6540)
#pragma warning(disable:
6540
)
__inline void* _MarkAllocaS(_Out_opt_ __crt_typefix(unsigned int*) void* _Ptr, unsigned int _Marker)
__inline
void
*
(
void
*
,
unsigned
int
)
{
if
(
)
{
*((
unsigned
int
*)
) =
;
_Ptr = (char*)_Ptr + _ALLOCA_S_MARKER_SIZE;
}
return
;
}
__inline
(
)
{
size_t _MarkedSize = _Size + _ALLOCA_S_MARKER_SIZE;
return
_MarkedSize
>
?
_MarkedSize
:
0
;
}
#pragma warning(pop)
#pragma warning(pop)
#endif
#ifdef _DEBUG
#ifndef _CRTDBG_MAP_ALLOC
#undef _malloca
#define _malloca(size) \
__pragma(warning(suppress: 6255 6386)) \
(_MallocaComputeSize(size) != 0 \
? _MarkAllocaS(malloc(_MallocaComputeSize(size)), _ALLOCA_S_HEAP_MARKER) \
: NULL)
#endif
#else
#undef _malloca
#define _malloca(size) \
__pragma(warning(suppress: 6255 6386)) \
(_MallocaComputeSize(size) != 0 \
? (((_MallocaComputeSize(size) <= _ALLOCA_S_THRESHOLD) \
? _MarkAllocaS(_alloca(_MallocaComputeSize(size)), _ALLOCA_S_STACK_MARKER) \
: _MarkAllocaS(malloc(_MallocaComputeSize(size)), _ALLOCA_S_HEAP_MARKER))) \
: NULL)
#endif
#if defined __midl && !defined RC_INVOKED
#elif defined _DEBUG && defined _CRTDBG_MAP_ALLOC
#else
#undef _freea
#pragma warning(push)
#pragma warning(push)
#pragma warning(disable: 6014)
#pragma warning(disable:
6014
)
__inline void __CRTDECL _freea(_Pre_maybenull_ _Post_invalid_ void* _Memory)
__inline
void
__cdecl
(
void
*
)
{
unsigned
int
;
if
(
)
{
_Memory = (char*)_Memory - _ALLOCA_S_MARKER_SIZE;
_Marker
= *(
unsigned
int
*)
;
if (_Marker == _ALLOCA_S_HEAP_MARKER)
{
(
);
}
#ifdef _ASSERTE
else if (_Marker != _ALLOCA_S_STACK_MARKER)
else
if
(
_Marker
!=
0xCCCC
)
{
_ASSERTE(("Corrupted pointer passed to _freea" && 0));
(
void
)( (!!(((
"Corrupted pointer passed to _freea"
&&
0
)))) || (
1
!=
(
2
,
L"c:\\program files (x86)\\windows kits\\10\\include\\10.0.17763.0\\ucrt\\malloc.h"
,
162
,
0
,
L"%ls"
,
L"(\"Corrupted pointer passed to _freea\" && 0)"
)) || (__debugbreak(),
0
) );
}
#endif
}
}
#pragma warning(pop)
#pragma warning(pop)
#endif
#if _CRT_INTERNAL_NONSTDC_NAMES
#define alloca _alloca
#endif
_CRT_END_C_HEADER
#endif // _INC_MALLOC