Yes, it's a pointer to a pointer, or a variable who's contents point to another variable who's content is a pointer. Heh.
I use type Ptr Ptr far too much, I think.
BlitzMax arrays use it internally, for accessing the array contents.
It can be useful in different ways.
For iterating over a block of pointers :
SuperStrict
Framework brl.standardio
Local p:Byte Ptr = MemAlloc(4 * 20)
Local iter:Int Ptr Ptr = Int Ptr Ptr (p)
For Local i:Int = 0 Until 20
iter[i] = 0 ' some pointer to somewhere
Next
Here's another not-so-useful piece of code which demonstrates... hmm... something. Imagine, if you will, that we need to use some external process to allocate some memory that we want to use. We create a byte ptr variable, and send the address of that variable to the external allocation function. When the function returns, we have a block of memory pointed to by our variable.
SuperStrict
Framework brl.standardio
Local p:Byte Ptr
externalMemAlloc(Varptr p)
For Local i:Int = 0 Until 128
Print p[i]
Next
externalMemFree(Varptr p)
Function externalMemAlloc(p:Byte Ptr Ptr)
p[0] = MemAlloc(128)
populate(p[0])
End Function
Function externalMemFree(p:Byte Ptr Ptr)
MemFree(p[0])
End Function
Function populate(p:Byte Ptr)
For Local i:Int = 0 Until 128
p[i] = i
Next
End Function
And so it turns out I'm not very good at explaining it very well :-p
|