现在的位置: 首页 > 综合 > 正文

alloca()与malloc的区别

2013年02月15日 ⁄ 综合 ⁄ 共 479字 ⁄ 字号 评论关闭

void*   realloc(void*   ptr,   unsigned   newsize);  
void*   malloc(unsigned   size);  

void*   alloca(unsigned   size);  

void*   calloc(size_t   numElements,   size_t   sizeOfElement);  
都在stdlib.h函数库内  

 

 

alloca 和malloc 的 区别我是alloca是在栈上申请  
malloc是在堆上申请

 

alloca
is not Standard and
cannot be used in programs which must be widely
portable,
no matter how useful it might be.
Now that C99 supports variable-length arrays (VLA's),
they can be used to more cleanly accomplish
most of the tasks which alloca
used to be put to.

void fun()

{

int size = INT_MAX / 8;
char a[size];

}

抱歉!评论已关闭.