[interprocess] Determine size of managed_shared_memory

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[interprocess] Determine size of managed_shared_memory

Kai Benndorf-2
Hi all,

I want to create a managed_shared_memory in exactly the size I needed.
Therefore I do something like this:

size = sizeof( common_managed_shared_memory );
size += sizeof( MyClassInSharedMem );

managed_shared_memory segment(create_only, "name", size );

MyClassInSharedMem allocates itself some memory by segment->allocate().
I added this also to the size, but get a boost::interprocess::bad_alloc
exception on allocating this additional memory.

Are there some magic bytes I forgot to add?

Many thanks in advance

Kai


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [interprocess] Determine size of managed_shared_memory

Ion Gaztañaga
On 05/08/2010 16:39, Kai Benndorf wrote:

> Hi all,
>
> I want to create a managed_shared_memory in exactly the size I needed.
> Therefore I do something like this:
>
> size = sizeof( common_managed_shared_memory );
> size += sizeof( MyClassInSharedMem );
>
> managed_shared_memory segment(create_only, "name", size );
>
> MyClassInSharedMem allocates itself some memory by segment->allocate().
> I added this also to the size, but get a boost::interprocess::bad_alloc
> exception on allocating this additional memory.
>
> Are there some magic bytes I forgot to add?

Yes, but you can't calculate it, because there are memory allocation
bookeeping and fragmentation issues that change in runtime depending on
your allocation/deallocation pattern. And shared memory is allocated by
pages by the OS (4K on linux 64k on windows), so any allocation will be
in practice allocated rounded to a page:

managed_shared_memory segment(create_only, "name", 20);

will waste the same memory as:

managed_shared_memory segment(create_only, "name", 4096);

Ion
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [interprocess] Determine size of managed_shared_memory

Boost - Users mailing list
Hi,

I want to continue on this topic.
when i have created the maximum number of objects needed in the application
in shmem,
 the consumed memory is n bytes.(managed_shm.get_size() -
managed_shm.get_free_memory();)
However, during run time these objects can be deleted and created multiple
times causing fragmentation.

Is there a recommended size that can safe against bad_allocs due to
fragmentation (like 2n, 3n)?

-Vivek



--
Sent from: http://boost.2283326.n4.nabble.com/Boost-Users-f2553780.html
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users