[gecode-users] pointer safe (sorry for multiple posting)

Mauricio Toro mauriciotorob at gmail.com
Thu May 29 15:46:42 CEST 2008


And what about IntVars? can I use references two?for example:

IntVar * get_IntVar(Space * h,IntVar * pos, IntVarArray & array)
{
     IntVar * answer = new IntVar(h,1,1000);
     element(h, array, *pos, *answer);
     return answer;
}

IntVar & get_IntVar(Space * h,IntVar & pos, IntVarArray & array)
{
     IntVar answer(h,1,1000);
     element(h, array, pos, answer);
     return answer;
}

Are both "pointer safe"?
I mean, is it necesary to allocate memory
for IntVars using new, or when I create the IntVar object
it allocates its own memory?

Thank you very much,

Mauricio

2008/5/29 Christian Schulte <cschulte at kth.se>:

>  Just pass arrays by reference and not by value!
>
>
>
> Christian
>
>
>
> --
>
> Christian Schulte, www.ict.kth.se/~cschulte/
>
>
>
> *From:* users-bounces at gecode.org [mailto:users-bounces at gecode.org] *On
> Behalf Of *Mauricio Toro
> *Sent:* Thursday, May 29, 2008 3:34 PM
> *To:* users at gecode.org
> *Subject:* [gecode-users] pointer safe (sorry for multiple posting)
>
>
>
> Hello all,
>
>
>
> I would like to know if this functions are "pointer safe",
>
> I was looking at the array implementation and I think
>
> it manage its own memory allocation.
>
>
>
> IntVarArray create(Space * h, int size)
>
> {
>
>    return IntVarArray(h,size,1,1000);
>
> }
>
>
>
> IntVar * get_IntVar(Space * h,IntVar * pos, IntVarArray array)
>
> {
>
>      IntVar * answer = new IntVar(h,1,1000);
>
>      element(h, array, *pos, *answer);
>
>      return answer;
>
> }
>
>
>
> IntVar * get_IntVar(Space * h,int pos, IntVarArray array)
>
> {
>
>      return &array[pos];
>
> }
>
>
>
> I tried using new with IntVarArray but it not allowed.
>
> Is there a problem of creating an IntVarArray in a function and returning
> it?
>
> is there a problem with the other two?
>
>
>
> Thanks
>
> --
> Mauricio Toro Bermudez
> Estudiante de Ingeniería de Sistemas
> Pontificia Universidad Javeriana, Colombia
>
> Stagiare à l'Ircam
> 1, place Igor-Stravinsky 75004 Paris,
> France de 2008 à 2009
>
>
>
>
> --
> Mauricio Toro Bermudez
> Estudiante de Ingeniería de Sistemas
> Pontificia Universidad Javeriana, Colombia
>
> Stagiare à l'Ircam
> 1, place Igor-Stravinsky 75004 Paris,
> France de 2008 à 2009
>



-- 
Mauricio Toro Bermudez
Estudiante de Ingeniería de Sistemas
Pontificia Universidad Javeriana, Colombia

Stagiare à l'Ircam
1, place Igor-Stravinsky 75004 Paris,
France de 2008 à 2009
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.ps.uni-sb.de/pipermail/users/attachments/20080529/830958d6/attachment.htm>


More information about the gecode-users mailing list