The MASM Forum

Projects => ObjAsm => Topic started by: HSE on February 09, 2016, 11:54:47 AM

Title: LinkedList: Clear
Post by: HSE on February 09, 2016, 11:54:47 AM
Hi!!

I'm trying to put some order in my code.

One thing I see is I'd make some changes to ObjAsm32, and that make my code not portable, so now I'm moving that modifications inside the projects.

An almost indispensable LinkedList method is Clear (the same that Done but without Done and pFirstNode= NULL). Perhaps that method must be included in a next ObjAsm32 version.

Regards. HSE


Title: Re: LinkedList: Clear
Post by: Biterider on February 09, 2016, 05:38:41 PM
Hi HSE
Thanks for the contribution. I'll add it for the next release.

Biterider
Title: Re: LinkedList: Clear
Post by: Biterider on February 09, 2016, 06:12:24 PM
Hi
I reformulate Clear and Done methods a bit. Waht do you think about these changes?
Biterider
Title: Re: LinkedList: Clear
Post by: HSE on February 10, 2016, 03:03:25 AM
Hi Biterider!

Clear must left NULL in pFirstNode. Perhaps a more robust method also need to left NULL in pLastNode and pCurrentNode, and 0 in dCount, but I only evaluate pFirstNode (method Append also evaluate pFirstNode). If pFirstNode is NULL then LinkedList is empty. I have never used dCount, but I'm seeing now, perhaps is very usefull.

Thanks. HSE

LATER: Apparently ecx need to be preserved.


Title: Re: LinkedList: Clear
Post by: Biterider on February 10, 2016, 06:37:03 AM
Hi HSE
You are correct. I would suggest to change the resetting block to the top to avoid the push/pop ecx like
Method LinkedList.Clear, uses esi
    SetObject ecx
    mov esi, [ecx].LinkedList.pFirstNode
    mov [ecx].dCount, 0
    mov [ecx].pFirstNode, NULL
    mov [ecx].pLastNode, NULL
    mov [ecx].pCurrentNode, NULL
    .while esi != NULL
      Destroy [esi].LINKED_NODE.pObject                 ;Save dispose of linked Object
      push [esi].LINKED_NODE.pLinkFwrd                  ;Preserve address of next node
      MemFree esi                                       ;Free the linked node
      pop esi                                           ;Restore address of next node
    .endw
MethodEnd


Biterider
Title: Re: LinkedList: Clear
Post by: HSE on February 10, 2016, 08:54:43 AM
Perfect  :t I noted that a minute later (later to last "later"!), but I don't saw for a year.
Title: Re: LinkedList: Clear
Post by: LiaoMi on May 16, 2016, 10:31:02 PM
Hallo,

can this code be adapted to a 64 bit system? I would like to use a linked list for the 64 bit system, but dont know if I can use ObjAsm.

Regards
Title: Re: LinkedList: Clear
Post by: HSE on May 18, 2016, 07:52:00 AM
Hi LiaoMi!

64 bit: I don't know.

If you need to develop a OOP project you can try ObjAsm.

See http://masm32.com/board/index.php?topic=4287.0

In particular http://masm32.com/board/index.php?topic=4287.msg45798#msg45798

You can build a LinkedList in plain MASM
Title: Re: LinkedList: Clear
Post by: LiaoMi on May 23, 2016, 08:27:24 PM
Quote from: HSE on May 18, 2016, 07:52:00 AM
Hi LiaoMi!

64 bit: I don't know.

If you need to develop a OOP project you can try ObjAsm.

See http://masm32.com/board/index.php?topic=4287.0

In particular http://masm32.com/board/index.php?topic=4287.msg45798#msg45798

You can build a LinkedList in plain MASM

Hi HSE!

Thank you very much, this theme really helped me!
Title: Re: LinkedList: new methods
Post by: HSE on July 03, 2016, 05:29:55 AM
Two new methods:


; ——————————————————————————————————————————————————
; Method:    LinkedList.Clean
; Purpose:   Free all allocated resources.
; Arguments: None.
; Return:    Nothing.
Method LinkedList.Clean, uses esi
    SetObject ecx
    mov esi, [ecx].LinkedList.pFirstNode
    mov [ecx].pFirstNode, NULL
    mov [ecx].pLastNode, NULL
    mov [ecx].pCurrentNode, NULL
    mov [ecx].dCount, 0
    .while esi != NULL
      push [esi].LINKED_NODE.pLinkFwrd                  ;Preserve address of next node
      MemFree esi                                       ;Free the linked node
      pop esi                                           ;Restore address of next node
.endw
MethodEnd



; ——————————————————————————————————————————————————
; Method:    LinkedList.DoneClean
; Purpose:   Finalize the LinkedList object and free all allocated
;            resources.
; Arguments: None.
; Return:    Nothing.
Method LinkedList.DoneClean
    OCall Clean
    ACall Done
MethodEnd


These are usefull when using LinkedList to store dwords instead pointers(I'm storing commands). In that case Clear throw errors because there is no objects to destroy.