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, the stackAlloc function stackAlloc always use malloc instead of alloca , everything will work.
I changed the function to a macro, and now it works as expected:
#define maxStackAllocation 1024 #define stackAlloc(size) \ ( \ (size > maxStackAllocation)? \ malloc(size): \ _alloca(size) \ ) #define stackAllocFree(ptr, size) \ ( \ (size > maxStackAllocation)? \ free(ptr): \ void() \ )
source share