Boost logo

Boost Users :

From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2006-10-09 15:55:23


Hi Andrea,

> The domain of the application is centered on the passing of image frames
> from process that acquires the images to the client process via a local
> shared memory segment.

Ok.

> If I open the segment with the exact number of bytes needed:
>
>> const int memsize = 320*240;
>> //Create shared memory
>> if(!segment.open_or_create(shMemName, memsize)){
>> std::cout << "error creating shared memory\n";
>> return -1;
>> };
>
> Then I cannot use:
>
>> unsigned char* uchar_ptr = (unsigned char*)segment.allocate(num_elements);

Because the shared memory segment is not a trivial shm_open + mmap-like
shared memory. It has dynamic allocation, a named parameter index
type... so it wastes memory. The size passed in open is the shared
memory size (well, more or less). Each allocate() call needs to keep
track of the allocated size, to be able to deallocate it when the user
calls deallocate().

In short, there is no way to know beforehand how much space it will be
wasted in bookkeeping, since it depends on the number of allocations,
the alignment, the number of named parameters, their length, the type of
index...

If you need a raw, classic shared memory, I would recommend you to use
Boost.Interprocess:

http://boost-consulting.com/vault/index.php?&direction=0&order=&directory=Concurrent%20Programming

Interprocess is the official Boost name for Shmem. I surely will remove
Shmem from the vault soon because I want people to use Interprocess. In
interprocess you can create a classic shared memory segment like this:

http://tinyurl.com/z5gyn

Regards,

Ion


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net