My stackAlloc
function looks like this:
void* stackAlloc(size_t size) {
if (size > maxStackAllocation)
return malloc(size);
else
return _alloca(size);
}
void stackAllocFree(void *ptr, size_t size) {
if (size > maxStackAllocation) {
free(ptr);
}
}
If I change so the stackAlloc
function always use malloc
instead of alloca
everything works.
I changed the function to a macro, and now its working as expected:
#define maxStackAllocation 1024
#define stackAlloc(size) \
( \
(size > maxStackAllocation)? \
malloc(size): \
_alloca(size) \
)
#define stackAllocFree(ptr, size) \
( \
(size > maxStackAllocation)? \
free(ptr): \
void() \
)