3

It looks like this:

MyType * pMy = my_segment->construct<MyType>(anonymous_instance)();
my_segment->destroy_ptr(pMy);

Where MyType is some typical struct and my_segment is correctly constructed boost::interprocess::managed_shared_memory * is around 10 times slower than the equivalent:

MyType * pMy = new MyType();
delete pMy;

I did not expect this. I though the two allocation algorithms should be similar in implementation and performance. Is there some good reason for such a huge difference.

Edit: The test was conducted over a huge number of iterations.

Yordan Pavlov
  • 1,303
  • 2
  • 13
  • 26

1 Answers1

0

Try multiple allocations and see if they are all slow or only the first. If only the first is slow, it could be because the page backing the shared memory needs to be committed (and not just reserved). If the page is commited it might still potentially have to be paged in (from the page/swap file).

Any slowness baring the initial allocation, can be attributed to a highly tuned free-store allocator (i.e., new) vs the mechanism that boost uses to manage "allocations" in the shared memory segment (e.g., boost might use portable and more expensive synchronization mechanism to serialize allocations).

Michael Goldshteyn
  • 71,784
  • 24
  • 131
  • 181