|
Boost : |
Subject: Re: [boost] boost interprocess / shared memory question
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2009-02-15 04:47:50
Naveen Santhanam wrote:
> Hello,
>
> We have a windows application (a process) that requires a large data
> file (approx. 100 MB) to perform a task. We have a master that launches
> several instances of this application. We would like to share the large
> data file across the processes such that, there is just one instance of
> the data file in physical memory without any disc access. Hence each
> application will have a small footprint in memory during execution. We
> have tried using a managed shared memory object from the
> boost::interprocess library to achieve this. However, this doesnt help
> us as the memory footprint of the application goes up upon access of the
> data file. Is there a way to achieve the desired single footprint
> memory sharing? Does this work as expected with other OSes?
When managed_shared_memory is used (in Windows this is emulated with a
temporary memory mapped file). The OS will allocate memory on demand as
you access the file, and that memory will be shared across processes:
although you see that each process has 100 MB extra memory, the global
used memory will grow only 100MB, because those 100MB are shared across
processes.
If you don't need managed features and just read raw data from a file,
you can use file_mapping and mapped_region to map /unmap a concrete
memory region and avoid mapping the whole file. But of course, this will
require much more manual work.
Regards,
Ion
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk