Type pointer variables s referencing each other?

Blitz3D Forums/Blitz3D Beginners Area/Type pointer variables s referencing each other?

Zethrax(Posted 2004) [#1]
Can anyone illuminate my vast levels of ignorance on what's going on in the code below? After the deletion of the type instance, 'btype.mytype' is set to null even though its contents were apparently not modified. Do type pointers reference each other, or is Blitz doing some sort of garbage collection on the pointers pointing to a deleted instance.

I guess this behaviour makes sense as it would cause serious issues if you attempted to access a deleted type via a copied type pointer.

Graphics 800,600

Type mytype
	Field x
End Type

atype.mytype = New mytype
btype.mytype = atype.mytype

If btype.mytype = Null Then Print "NULL BEFORE DELETE"

Delete atype.mytype

If btype.mytype = Null Then Print "NULL AFTER DELETE"

WaitKey ()

End



Floyd(Posted 2004) [#2]
You have one object, created with New. Both atype and btype point to it.

'Delete atype' deletes the object pointed to by atype, so btype now points at nothing.


soja(Posted 2004) [#3]
btype.mytype = atype.mytype

This line just refers to the *reference* of the type.
There is no "copy constructor" or duplication of the actual type inherent with the = operator. As Floyd implies, the only time a custom type is instantiated is when you use the New command.


Zethrax(Posted 2004) [#4]
I realize that there's no new type being created. I'm just curious about how this nullifying of copied pointers to deleted instances works, as I can see some interesting uses for it for dynamic garbage collection if this behaviour is consistant.

What I'd like to do basically is to be able to assign an effect to an entity. The effect has its details stored in a type object. The entity also has a type object associated with it which stores its details, and there is a function which deletes both the entity and its associated type object. The effect (rotation, for example) is updated in a For-Each-Next loop.

The problem is that the entity might be deleted by circumstances outside the effect update, in which case the code that updates the effect will end up trying to work with an entity that no longer exists. If I store a type pointer that points to the entity's associated type object, in the effect's type object, then when the effect is updated I can simply check if that pointer has suddenly become null and then delete the effect's type object to avoid a conflict.