Author Topic: LinkedList: Clear  (Read 1785 times)

HSE

  • Member
  • ****
  • Posts: 533
  • <AMD>< 7-32>
LinkedList: Clear
« 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



Biterider

  • Moderator
  • Member
  • *****
  • Posts: 113
  • ObjAsm32
    • ObjAsm32
Re: LinkedList: Clear
« Reply #1 on: February 09, 2016, 05:38:41 PM »
Hi HSE
Thanks for the contribution. I'll add it for the next release.

Biterider

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 113
  • ObjAsm32
    • ObjAsm32
Re: LinkedList: Clear
« Reply #2 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

HSE

  • Member
  • ****
  • Posts: 533
  • <AMD>< 7-32>
Re: LinkedList: Clear
« Reply #3 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.



Biterider

  • Moderator
  • Member
  • *****
  • Posts: 113
  • ObjAsm32
    • ObjAsm32
Re: LinkedList: Clear
« Reply #4 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
Code: [Select]
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

  • Member
  • ****
  • Posts: 533
  • <AMD>< 7-32>
Re: LinkedList: Clear
« Reply #5 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.

LiaoMi

  • Member
  • **
  • Posts: 145
Re: LinkedList: Clear
« Reply #6 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

HSE

  • Member
  • ****
  • Posts: 533
  • <AMD>< 7-32>
Re: LinkedList: Clear
« Reply #7 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

LiaoMi

  • Member
  • **
  • Posts: 145
Re: LinkedList: Clear
« Reply #8 on: May 23, 2016, 08:27:24 PM »
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

  • Member
  • ****
  • Posts: 533
  • <AMD>< 7-32>
Re: LinkedList: new methods
« Reply #9 on: July 03, 2016, 05:29:55 AM »
Two new methods:

Code: [Select]
; ——————————————————————————————————————————————————
; 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

Code: [Select]
; ——————————————————————————————————————————————————
; 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.