The MASM Forum

Projects => ObjAsm => Topic started by: HSE on September 15, 2020, 06:40:55 AM

Title: Checking object?
Post by: HSE on September 15, 2020, 06:40:55 AM
Hi Biterider!

There is some defined way to know if pointed direccion is an object?

I have an spaghetti that apparently try to destroy objects previously destroyed  :biggrin:

Thanks.
Title: Re: Checking object?
Post by: Biterider on September 16, 2020, 02:36:23 AM
Hi HSE
As you know, a pointer to an object instance is simply a pointer to a memory location. You can try to check if you can see a pattern in memory, but it is difficult and error-prone.
I also had this problem and I solved it by setting the object pointer to NULL immediately after destroying it.
This way I got an exception when I accidentally tried to access it.

I hope this helps a bit  :rolleyes:

Biterider
Title: Re: Checking object?
Post by: HSE on September 16, 2020, 05:11:13 AM
Hi Biterider!

Quote from: Biterider on September 16, 2020, 02:36:23 AM
You can try to check if you can see a pattern in memory, but it is difficult and error-prone.
Yes, I was thinking something like that. Perhaps was already maked...  :nie:

Quote from: Biterider on September 16, 2020, 02:36:23 AM
I also had this problem and I solved it by setting the object pointer to NULL immediately after destroying it. This way I got an exception when I accidentally tried to access it.
Yes, I have that exceptions from time to time  :biggrin:
Some problems arise when same object belong simultaneously to several lists or collections.
Fortunatelly I found yesterday problem, and I think I will not have that problem never more..  until tomorrow :biggrin:
Perhaps next time I will try to make something.

Thanks.

HSE

Title: Re: Checking object?
Post by: Biterider on September 16, 2020, 03:40:13 PM
Hi HSE
I suspect your problem is more architecture related.  :rolleyes:

I recently developed an object that I had a similar problem with. I put all the object instances that the control manages in a master list, that was responsible for the life cycle of these objects.
Additionally I implemented other lists to handle the logic of the control. These lists were XWCollections that only stored the instance pointers and did not destroy the object when an item of the list was deleted.

Regards, Biterider



Title: Re: Checking object?
Post by: HSE on September 17, 2020, 12:41:02 AM
Hi Biterider!

Quote from: Biterider on September 16, 2020, 03:40:13 PM
I suspect your problem is more architecture related.  :rolleyes:
Exactly  :biggrin:

Quote from: Biterider on September 16, 2020, 03:40:13 PM
I recently developed an object that I had a similar problem with. I put all the object instances that the control manages in a master list, that was responsible for the life cycle of these objects.
I maked that collections  :thumbsup:

Quote from: Biterider on September 16, 2020, 03:40:13 PM
Additionally I implemented other lists to handle the logic of the control. These lists were XWCollections that only stored the instance pointers and did not destroy the object when an item of the list was deleted.
Just in case I maked:
Method Vector.Clean, uses xbx xsi xdx
    SetObject xsi
    mov xbx, [xsi].dCount
    mov xdi, [xsi].pItems
    or xbx, xbx
    jmp @@1
align ALIGN_CODE
@@0:
    mov POINTER ptr [xdi], NULL
    add xdi, sizeof POINTER
    dec xbx
@@1:
    jnz @@0
    m2z [xsi].dCount
MethodEnd


but in practical terms you only need:mov [xax].Vector.dCount, 0

Regards. HSE