我的stackAlloc
功能如下所示:
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);
}
}
如果我改变所以stackAlloc
函数总是使用malloc
而不是alloca
一切正常。
我将函数更改为宏,现在它按预期工作:
#define maxStackAllocation 1024
#define stackAlloc(size) \
( \
(size > maxStackAllocation)? \
malloc(size): \
_alloca(size) \
)
#define stackAllocFree(ptr, size) \
( \
(size > maxStackAllocation)? \
free(ptr): \
void() \
)