如果在一个函数里面分配内存,在函数退出时释放内存的情况下可以使用_alloca代替malloc。前者
是可以在函数退出时自动释放内存块,而不用显式使用free函数,而且在堆栈中分配内存可以减少
在堆中分配内存的缺点---产生内存碎片。

alloca allocates size bytes from the program stack. The allocated space is automatically freed when the calling function exits (not when the allocation merely passes out of scope). Therefore, do not pass the pointer value returned by _alloca as an argument to free.

详细用法请参考msdn

posted on 2005-12-31 15:22 Jeffrey.Coding 阅读(222) 评论(0)  编辑 收藏 引用 所属分类: 技术点

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理