[gecode-users] Memory management bug in 2.2.0?
Filip Konvička
filip.konvicka at logis.cz
Fri Mar 27 08:46:32 CET 2009
Hi Guido,
> 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.
thanks for the explanation. The workaround for 2.2.0 is simple:
struct MySpace : Space {
BoolVarArray bva;
MySpace(...) {
std::vector<BoolVar> bva_;
...
bva_.push_back(v);
...
BoolVarArray tmp(this, bva_.size());
for(int i=bva_.size()-1; i>=0; --i)
tmp[i]=bva_[i];
bva=tmp;
...
}
...
};
Cheers,
Filip
More information about the gecode-users
mailing list