News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

LinkedList: Clear

Started by HSE, February 09, 2016, 11:54:47 AM

Previous topic - Next topic

HSE

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


Equations in Assembly: SmplMath

Biterider

Hi HSE
Thanks for the contribution. I'll add it for the next release.

Biterider

Biterider

Hi
I reformulate Clear and Done methods a bit. Waht do you think about these changes?
Biterider

HSE

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.


Equations in Assembly: SmplMath

Biterider

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

HSE

Perfect  :t I noted that a minute later (later to last "later"!), but I don't saw for a year.
Equations in Assembly: SmplMath

LiaoMi

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

HSE

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
Equations in Assembly: SmplMath

LiaoMi

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!

HSE

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.   
Equations in Assembly: SmplMath