boost::interprocess::managed_shared_memory: Grow(): Memory Reused?

风流意气都作罢 提交于 2019-12-24 13:55:55

问题


I am using boost::interprocess::managed_shared_memory. Initially I allocate say X mb memory. When process ran out of memory, we grow the memory by a fixed value (say Y mb, perform unmap-> grow()-> map)

While growing, if contiguous memory is not available then a new chunk with X+Y mb is allocated with a different base address. What happens to previously allocated X mb chunk? Does boost take care of deleting it since it is already unmapped and no process is referring to it?


回答1:


Shared memory is a platform specific service.

Shared memory is by definition virtual.

Most of all is not allocated from the program heap. Shared memory is mapped into the process space by the OS.

With all of the above

  • it's platform defined whether the memory is reused (reuse here would simply mean whether the pages that are in-memory at the time are kept; if the address is changed, this means nothing in reality, because it's just the same pages getting remapped to a different virtual address in process space).

In other words (as you already half-hinted at), after the memory is unmapped, boost has nothing to delete, because nothing was ever allocated from the heap in the first place.



来源:https://stackoverflow.com/questions/22684861/boostinterprocessmanaged-shared-memory-grow-memory-reused

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!