[Coin-discuss] BCP_vec<double> memory allocation

Daniel Lichtenberger daniel.lichtenberger at gmx.net
Mon Oct 25 13:00:29 EDT 2004


Hi!

I'm using COIN/Bcp to build a local branching framework, and I've run into 
problems using lots of BCP_vec<double> objects (or storing many objects 
containing BCP_vec<double> objects, like BCP_solution_generic). The program 
segfaults after allocating a few thousand objects. I looked through the Bcp 
sources, and noticed that BCP_vec<double> allocates a lot of memory in 
advance - so much that even virtual memory seems to run out.

In
BCP_vec<double>::insert_aux(iterator position, const_reference x)
these lines seem to allocate extra memory when the container gets too small 
(BCP_vector_double.cpp):

      const size_t len = (2*size() + 0x1000) * sizeof(double);
      iterator tmp = allocate(len);

allocate is defined in BCP_vector.hpp:

   inline iterator allocate(size_t len) {
      return static_cast<iterator>(::operator new(len * sizeof(T)));
   }
 
So when a BCP_vec<double> runs out of space, it allocates at least 
0x1000 * 8 * 8 = 256 kb of memory (assuming a double is 8 bytes). Since a 
BCP_vec is initialized with a capacity of 0, each BCP_vec<double> takes 256 
KB once a value has been inserted, like:

        BCP_vec<double>* v = new BCP_vec<double>;
        v->push_back(1);

I've run some quick tests that seem to back this assumption (on my x86 
machine). Is this a bug or intended behaviour?

Thanks,
Daniel



More information about the Coin-discuss mailing list