1

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?

manlio
  • 18,345
  • 14
  • 76
  • 126
user1989504
  • 133
  • 1
  • 13

1 Answers1

2

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.

sehe
  • 374,641
  • 47
  • 450
  • 633
  • Thank you for your reply. This means unlike malloc (where we need to explicitly delete the allocated memory), after growing shared memory there is no need to worry about managing previously allocated memory. Unmapping in itself means that memory/virtual address is available for reuse? – user1989504 Mar 28 '14 at 03:42
  • Yes. This is what I said. Well, tried to say, anyways :) – sehe Mar 28 '14 at 06:50