English 中文(简体)
如果我用微粒而不是小鼠来分配记忆?
原标题:What if I allocate memory using mmap instead of malloc?

使用<代码>mmap分配记忆有什么缺点。 (与MAP_PRIVATE和MAP_ANONYMOUS)相比,使用malloc? 关于职能范围的数据,我将使用中记,因此不使用<条码>。

One disadvantage that comes to mind is for dynamic data structures such as trees and linked lists, where you frequently require to allocate and deallocate small chunks of data. Using mmap there would be expensive for two reasons, one for allocating at granularity of 4096 bytes and the other for requiring to make a system call.

但在其他情况下,你是否认为<代码>小<>/代码>优于<代码>mmap/code>? 其次,我对动态数据结构的<代码>mmap的不利程度是否过高?

<代码>mmap>>>> <代码>>(<0>> 我可以认为,当你读到munmap时,即立即将记忆归还本组织,而用malloc/free,我猜测,直到数据部分的中断点永远不会再回来,但可以重新使用。

问题回答

是的,malloc优于mmap。 它更便于使用,更微薄,更便于使用。 结尾处将打电话<代码>mmap。

如果你开始用<代码>mmap<>进行日常记忆管理,你就希望以比页数小的平方位实施某种方式包裹,并且你将最终重新实施<代码>小型<<<>><>>>>(<0>>>>>>>/代码>——可能是一种次优的方式。

首先,mmap()是一个平台,其具体内容是,如果你计划用便携式C书写,就已经过时。

其次,malloc() 基本上按mmap()执行,但围绕系统电话收集某种智慧的图书馆:必要时,它将要求系统提供新的记忆,但直到那时,该系统将在一个已经致力于这一进程的领域收集一个记忆。

因此,如果你想进行普通的活期记忆分配,则使用<代码>小范围(>,结束故事。 用于记忆分配的<代码>mmap(>>)应保留给特殊情况(例如,如果你实际上想要一整页的海隆,在页面边界上加以调整),并且总是抽取成一个单一的图书馆代码,以便其他人能够轻易地理解你所做的事情。

mmap,malloc don t,mmap 允许你使用Huge页(flag case has MAP_HUGETLB set),而malloc 没有这种选择。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签