List of typed pointers

Share your advanced PureBasic knowledge/code with the community.
Rinzwind
Enthusiast
Enthusiast
Posts: 638
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

List of typed pointers

Post by Rinzwind »

I didn't know this feature... but experimenting shows it's working.
Normally a list handles its structures itself. An assignment makes a copy of the structure. Here we just pass pointers directly, saving memory etc.

Code: Select all

EnableExplicit

Structure Test
  Name.s
EndStructure

Define a.Test
a\Name = "Test"

NewList *l.Test()

AddElement(*l())
*l() = a ; assign a memory reference

Debug @a\Name
Debug @*l()\Name ;same address

Debug *l()\Name
So basically a typed pointer list. Better than using a generic .i list.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: List of typed pointers

Post by Josh »

I use this a lot. Especially useful are PointerMaps, where several lists can easily be linked to one search index.
sorry for my bad english
Post Reply