[Coin-discuss] BCP_vec<double> memory allocation
Laszlo Ladanyi
ladanyi at us.ibm.com
Mon Oct 25 21:52:23 EDT 2004
The answer is both... Intended behavior and bug. Intended, because I wanted to
allocate enough memory so that vectors of size around 10-100 (which in my
guess are the most frequent sizes) would not need any reallocation. The 0x1000
is probably a bug, it is way more then is necessary, I think. Probably I
wanted 0x100. Also, the * sizeof(double) is a bug, since it makes no sense to
multiply with teh size of the object both in push_back and in allocate.
I have fixed both sort of bug and committed the changes.
--Laci
On Mon, 25 Oct 2004, Daniel Lichtenberger wrote:
> 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
> _______________________________________________
> Coin-discuss mailing list
> Coin-discuss at www-124.ibm.com
> http://www-124.ibm.com/developerworks/oss/mailman/listinfo/coin-discuss
>
More information about the Coin-discuss
mailing list