[gecode-users] Memory management bug in 2.2.0?
Guido Tack
tack at ps.uni-sb.de
Thu Mar 26 22:50:17 CET 2009
Hi Filip,
the idea was (and still is) to initially allocate all VarArrays from
the space, and only when they are resized (by using add), the array is
copied to the heap. That way, most arrays are still efficiently
allocated in the space (e.g. copying an array always allocates it in
the space again).
The invariant I had in mind (and which now actually works only since
3.0.0) is the following: the array has been allocated from the space
iff used==n (and we renamed used to n and n to capacity...).
If you're interested in the correct invariants (or back-porting stuff
to 2.2.0), they are documented in gecode/kernel/array.hpp in the
current version.
Cheers,
Guido
Christian Schulte wrote:
> Hi Filip,
>
> yes that was strange stuff and we fixed for 3.0.0... Guido knows
> more about
> it.
>
> Christian
>
> --
> Christian Schulte, www.ict.kth.se/~cschulte/
>
>
> -----Original Message-----
> From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On
> Behalf
> Of Filip Konvicka
> Sent: Wednesday, March 25, 2009 2:18 PM
> To: users at gecode.org
> Subject: [gecode-users] Memory management bug in 2.2.0?
>
> Hi,
>
> I know I'm probably late with this... I am hunting a memory leak in a
> program that uses Gecode 2.2.0. The script (space) constructor
> incrementally adds variables to a var-array (one by one). IMHO,
> VarArray::resize acts strangely:
>
> VarArray<Var>::resize(Space* home, int m) {
> ...
> x = static_cast<Var*>(Memory::malloc(sizeof(Var)*newsize));
> ...
> if (used != n)
> Memory::free(oldx);
> else
> home->reuse(oldx, n);
> n = newsize; used = m;
> }
>
> In my case, "used==n" always holds, so the allocated blocks are
> "deallocated" using Space::reuse(), not Memory::free().
>
> Originally, I was using the default constructor for the array. After I
> saw this I tried to initialize it with (this, 0) in the constructor
> initializer list, but this does not change anything.
>
> It seems to me that VarArray::add and VarArray::resize could never
> actually work... the only way the var-array allocates memory from
> space
> is in the constructor and update(). Or did I miss something in the
> docs?
> Is it forbidden to call add and resize?
>
> Thanks,
> Filip
>
>
> _______________________________________________
> Gecode users mailing list
> users at gecode.org
> https://www.gecode.org/mailman/listinfo/gecode-users
>
>
> _______________________________________________
> Gecode users mailing list
> users at gecode.org
> https://www.gecode.org/mailman/listinfo/gecode-users
More information about the gecode-users
mailing list