gpt4 book ai didi

linux - Mac OS X 中是否有等同于 mallopt() 的函数?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:47:07 25 4
gpt4 key购买 nike

Linux 通过 mallopt() 为内存分配提供自定义选项。是否有类似的选项可用于在 OS X (BSD) 上自定义内存分配?

最佳答案

OS X 过去包含 mallopt() 函数,尽管现在它释放内存的方式与过去不同,因此您需要在 10.7 及更高版本中寻找替代方案。目前还不清楚您正在寻找哪种类型的特定 mallopt() 内存分配选项,尽管大多数等效函数都可以在以下 header 中找到:

/usr/include/malloc/malloc.h
/usr/include/mach/vm_map.h

您可能会发现与 mallopts() 功能相似的函数:

ma​​lloc_zone_pressure_relief()

advises the malloc subsystem that the process is under memory pressure and that the subsystem should make its best effort towards releasing (i.e. munmap()-ing) "goal" bytes from "zone". If "goal" is passed as zero, the malloc subsystem will attempt to achieve maximal pressure relief in "zone". If "zone" is passed as NULL, all zones are examined for pressure relief opportunities. malloc_zone_pressure_relief() returns the number of bytes released.

vm_allocate()

allocates a region of virtual memory in the specified task's address space. A new region is always zero filled.

OS X Memory Usage Performance Guidelines

关于linux - Mac OS X 中是否有等同于 mallopt() 的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35904357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com