5

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?

Dejwi
  • 4,393
  • 12
  • 45
  • 74

1 Answers1

6

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.

rodrigo
  • 94,151
  • 12
  • 143
  • 190
  • Oh. So simple. I must admit I was bountting after solving similar challenges directly on POSIX mmap and using Boost IOstreams. See e.g this answer [how to swap one line with another in c++](http://stackoverflow.com/a/17374711/85371). I wonder how they implemented it to be portable. – sehe Dec 12 '13 at 07:30