Hi Gustavo,
you can allocate from the general heap, which is available in Gecode through
the Heap class and the global object called heap. Furthermore, to get sharing
right, you should derive from the SharedHandle/SharedObject infrastructure we
provide. Just have a look at how SharedArrays are implemented, for example.
They have exactly the behavior you describe.
Cheers,
Guido
Gustavo Gutierrez wrote:
> Dear all,
>
> I am trying to implement something which at a first sight could look weird
> and have a memory problem, I will try to be as concise as possible while
> giving enough details to have some help from you; if you need to know more, I
> don't have any problem to explain my situation in a deeper way.
>
> I have some data structures which are external to propagators but that I need
> to share among computation spaces. Still, I would like to have this data
> structures allocated in some way by gecode itself and not from using new
> (malloc). Let's have a look at the following example of a main program
> creating some instances of Space:
>
>
> opt.parse(argc,argv);
> Space *sp = new Simple(opt);
> sp->status();
> Space *csp = sp->clone(true);
> csp->status();
> //delete sp;
> Space *csp2 = csp->clone(true);
>
>
> Just assume that there are no propagators posted during the construction of
> Simple, just a branching. Now, If I am right, by sending true to clone will
> cause the data structures (variables, etc) to be shared. Then csp will share
> data structures with sp. Now, I am considering to clone (and share again the
> data structures) csp into csp2. If at some point, I decided to delete sp I
> will get a memory problem, this is, there are data structures inside csp2
> that are supposed to *point* to something that where in sp but now is
> deallocated.
>
> I am using the space allocator to allocate the data structures, so I think
> that a space is deallocated by removing its complete heap from memory. If I
> understand correctly, there is a one to one relation between a space and a
> space heap. In my case, I would like to allocate the data structures
> somewhere else in such a way that those are no removed when spaces are
> deallocated. Is it possible to do that in gecode?, is there some "general
> heap" from which I can allocate memory from?, if yes, is there an allocator
> to allocate memory from this part?.
>
> I would like the memory to be allocated by gecode because in that way (I
> think) it will be reported as part of the statistics when running a search
> engine. Also, the data structures I am using use reference counting for the
> memory management but are not thread safe so I would like to know how this
> would interact with parallel search engines. I don't want to cause any heap
> segmentation (I am not sure how much sensible is gecode to memory alignment
> in its heap and things like that) that severely affects gecode performance.
>
>
> Any comment is more than welcome and thanks in advance.
>
> Gustavo
>
> _______________________________________________
> Gecode users mailing list
> [email protected]
> https://www.gecode.org/mailman/listinfo/gecode-users
_______________________________________________
Gecode users mailing list
[email protected]
https://www.gecode.org/mailman/listinfo/gecode-users