Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost interprocess allocator - manage file size

At first I will outline the domain with source.

namespace bip=boost::interprocess;

typedef bip::allocator<int, bip::managed_mapped_file::segment_manager> allocator;
typedef bip::vector<int, allocator> vector;

bip::managed_mapped_file m_file(open_or_create, "./file", constant_value);    
bip::allocator alloc(m_file.get_segment_manager());
bip::vector *vec = m_file.find_or_construct<vector>("vector")(alloc);

I don't care about final size of an underlying file, but I cannot foresight this value. Is there any boost mechanism, which will handle resizing an underlying file? Or I have to catch bip::bad_alloc and care about this by my own?

like image 999
Dejwi Avatar asked Apr 03 '13 16:04

Dejwi


1 Answers

Read this this section of the docs.

You have the static member function grow() that may be what you need:

bip::managed_mapped_file::grow("./file", extra_bytes);

But you have to be sure that nobody is using the file, that's why they call it off-line growing. And that may not be possible depending on the problem.

like image 122
rodrigo Avatar answered Oct 12 '22 16:10

rodrigo