Re: Array as instance data

Jouni Miettunen (jouni.miettunen@ccc.fi)
Thu, 19 Dec 1996 10:27:18 +0200

Hello,

>> It would seem that the first 16 places are ok, but the next (or one after
>> that) corrupts memory == about when I try to write into array[1][1]..

Correction: another instance variable gets corrupted. One that is defined
just before the array.. I made it global and things seem to work. Maybe
something else is now corrupted, but I haven't found it.

>Is there a chance that your code is saving a pointer to the array, instead of
>using a chunkhandle? Pointers aren't dependable because of the memory
>swapping that the mem manager will do. You need instead, to use a handle to
>reference the array. If this isn't the problem, forgive my presumption.

I do some memory allocation and afterwards pself = ObjDerefVis(oself);
I access the array via pself->array[x][y]; That should not be a problem.

Things get corrupted when I do (below). Not always, but at the special
case of ending a for loop (x-coordinate), getting back to previous for
loop (y-coordinate) and starting a new round of the x-coordinate.. To
make things more weird the value of pself->size gets back correct at
the end of this for loop round, corrupt next time, correct etc.

for (y)
for (x)
@call childOptr::MSG_VIS_SET_SIZE(pself->size,pself->size);
end (x)
end (y)

As I said the fix was to make pself->size variable a global one..

>Lee

--jouni