Get List ObjectPointer

Share your advanced PureBasic knowledge/code with the community.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Get List ObjectPointer

Post by Josh »

Code: Select all

EnableExplicit


Structure LISTOBJECT
  *ListHeader
  *CurrentElement
EndStructure

Structure LISTHEADER
  *FirstElement
  *LastElement
  *CurrentElement
  *PtrToObject
  ListSize.i
  ListIndex.i
EndStructure


NewList MyList()
Define *ListObject.LISTOBJECT
Define *ListHeader.LISTHEADER

PushListPosition (MyList())
*ListObject = ResetList (MyList()) - SizeOf (Integer)
*ListHeader = *ListObject\ListHeader
PopListPosition (MyList())


AddElement (MyList())
AddElement (MyList())

Debug ""
Debug *ListHeader\FirstElement
Debug *ListHeader\LastElement
Debug *ListHeader\CurrentElement
Debug *ListHeader\ListSize

AddElement (MyList())
AddElement (MyList())

Debug ""
Debug *ListHeader\FirstElement
Debug *ListHeader\LastElement
Debug *ListHeader\CurrentElement
Debug *ListHeader\ListSize
Only testet on Windows
Unfortunately this trick doesn't work for maps :(
sorry for my bad english
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Get List ObjectPointer

Post by Kwai chang caine »

Works here :shock:
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Get List ObjectPointer

Post by davido »

@Josh,
Appears to work on my MacBook Pro.

Output:

Code: Select all

4298439048
4298439080
4298439080
2

4298439048
4298439144
4298439144
4


Model Name: MacBook Pro
Model Identifier: MacBookPro12,1
Processor Name: Dual-Core Intel Core i7

System Version: macOS 10.15.2 (19C57)
Kernel Version: Darwin 19.2.0
DE AA EB
Post Reply