[GAP Forum] Pointing objects and how to detect it

Sergio Siccha sergio at mathb.rwth-aachen.de
Thu Nov 8 13:19:45 GMT 2018


>> If one is given a matrix, is there a way to identify which one are
pointing
>> to another object? Because right now if one does not know how the objects
>> are built then I do not know how to do it.

If you want to make sure that no row of your matrix points to another
GAP object (which may not be part of your matrix) you can use
`StructuralCopy`. For documentation see:
?Duplication of Lists

As you can see in the documentation you then still have to check whether
two rows of the matrix are identical to each other.


Calling `StructuralCopy` on everything might be a bit overkill though. I
think documented GAP functions tell you whether they create new objects
or reuse the matrix you gave it.


Best,
Sergio

On 11/8/18 12:31 PM, Stephen Linton wrote:
> The function you want is called IsIdenticalObj. It’s documented in the manual.
> 
> gap> eList:=[0,0,0,0];
> [ 0, 0, 0, 0 ]
> gap> eL2:=[];
> [  ]
> gap> Add(eL2, eList);
> gap> Add(eL2, eList);
> gap> eL3:=[ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ];
> [ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ]
> gap> IsIdenticalObj(eL2[1],eL2[2]);
> true
> gap> IsIdenticalObj(eL3[1],eL3[2]);
> false
> gap> 
> 
> 
> 	Steve
> 
>> On 8 Nov 2018, at 11:02, Mathieu Dutour <mathieu.dutour at gmail.com> wrote:
>>
>> I have a question about memory management in GAP.
>>
>> If we do
>> eList:=[0,0,0,0];
>> eL2:=[];
>> Add(eL2, eList);
>> Add(eL2, eList);
>> The state of eL2 is then [ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ]
>> Now if we do eL2[1][1]:=1 then we have eL2 being
>> [ [ 1, 0, 0, 0 ], [ 1, 0, 0, 0 ] ]
>> because eL2 actually contains two pointers to eList.
>>
>> On the other hand, if we write eL3:=[ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ];
>> and do eL3[1][1]:=1 then we have eL3 being [ [ 1, 0, 0, 0 ], [ 0, 0, 0, 0 ]
>> ].
>>
>> Therefore the GAP object behavior depend on the way they are
>> constructed.
>>
>> If one is given a matrix, is there a way to identify which one are pointing
>> to another object? Because right now if one does not know how the objects
>> are built then I do not know how to do it.
>>
>>  Mathieu
>> _______________________________________________
>> Forum mailing list
>> Forum at gap-system.org
>> https://mail.gap-system.org/mailman/listinfo/forum
> 
> _______________________________________________
> Forum mailing list
> Forum at gap-system.org
> https://mail.gap-system.org/mailman/listinfo/forum
> 



More information about the Forum mailing list