释放分配给alloca的内存 [英] Freeing alloca-allocated memory

查看:280
本文介绍了释放分配给alloca的内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在当前函数退出之前,是否可以显式释放C的alloca()分配的内存?如果可以,怎么办?

Is it possible to free memory allocated by C's alloca() explicitly, before the current function exits? If so,how?

推荐答案

可以,但是没有预先编写的函数可以执行此操作.您必须深入研究编译器的alloca()实现,以弄清它在做什么,然后编写自己的freea().由于每个编译器对alloca()的处理方式都不同,因此您必须为每个编译器重写freea().

It is possible, but there is no pre-written function to do it. You'd have to delve into your compiler's implementation of alloca() to figure out what it is doing, then write your own freea(). Since every compiler does alloca() differently, you'd have to rewrite your freea() for each compiler.

但是我很难相信这将是值得的麻烦.如果需要显式释放它,则只需使用malloc/free -这些功能通常进行了优化.利用它们.

But I find it hard to believe this would be worth the trouble. Just use malloc/free if you need to explicitly free it - those functions are usually heavily optimized. Take advantage of them.

这篇关于释放分配给alloca的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆