如何使用自定义malloc操纵堆大小?(C ++ LLVM) [英] How to manipulate heap size with custom malloc? (C++ LLVM)

查看:61
本文介绍了如何使用自定义malloc操纵堆大小?(C ++ LLVM)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道可以覆盖malloc,realloc,free等.

I know it's possible to overwrite malloc, realloc, free, etc.

但是我没有看到一种根据需要操纵堆大小的方法.如何根据需要增大/缩小?

But I'm not seeing a way to manipulate the heap size as needed. How can I grow/shrink this as needed?

推荐答案

堆是malloc从中返回内存的堆.

The heap is that from which malloc returns memory.

malloc()的古老实现将返回使用free()释放的内存(如果有的话),否则使用 mmap("/dev/zero")或类似版本反而.其他操作系统通常与这两者之一相似.

Ancient implementations of malloc() would return memory that had been freed using free() if any was available, else request more memory from the unix kernel using sbrk(). More modern ones tend to use mmap("/dev/zero") or similar instead. Other operating systems generally are similar to one or both.

对堆大小的限制既可以在malloc本身中实现,也可以在malloc使用的OS机制中实现.

Limitations on heap size may be implemented either in malloc itself or in the OS mechanism that malloc uses.

这篇关于如何使用自定义malloc操纵堆大小?(C ++ LLVM)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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