问题
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