我如何释放被SBRK获得内存()? [英] How do I free memory obtained by sbrk()?

查看:181
本文介绍了我如何释放被SBRK获得内存()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用SBRK()来获取存储自定义分配器的功能。
我如何释放这个内存时,它不再需要?

I have a custom allocator function which uses sbrk() to obtain memory. How do I release this memory when it's no longer needed?

是否有一个功能相当于给free()的malloc()函数?

Is there a function equivalent to free() for malloc() ?

或做我必须使用BRK()来设置数据段的结束?

or do I have to use brk() to set the end of the data segment ?

推荐答案

您需要使用 BRK SBRK 再次萎缩。

You need to use brk or sbrk again to shrink.

在你到底有没有修改的内存(除了像系统调用MMAP)量的唯一途径,就是增加或减少堆,让你与 SBRK BRK 键,您将它打倒 BRK SBRK 带负增长。

In the end the only way you have to modify the amount of memory(apart from mmap like syscalls), is to increase or decrease the heap, so you move it up with sbrk or brk and you move it down with brk or sbrk with a negative increment.

这篇关于我如何释放被SBRK获得内存()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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