Displaying and storing memory addresses

BlitzMax Forums/BlitzMax Programming/Displaying and storing memory addresses

Drey(Posted 2006) [#1]
Hey, when using pointers i want to either:

Have an array of pointers..which isn't seeming likely. Similar to the idea of:

Global Array_Of_Pointer:Float Ptr[4]

Instead i had the idea to do this

Global Array_of_Addresses:Int [4]

Global X_Ptr:Float Ptr
Global X:Float

X_Ptr = Varptr X[0]

Array_of_Addresses[0]= X_Ptr

DrawText X_Ptr,0,0



I know a pointer isn't a string, but i want it's address to be displayed and stored. How do i go about doing that?



[/code]


DStastny(Posted 2006) [#2]
Is this what you want?

Strict
Graphics 640,480,0
Local X:Int=5
Local pX: Int Ptr = Varptr(x)
Local addresses: Int Ptr[2]
addresses[0]=px

While Not AppTerminate()
	DrawText "Hex="+Hex(Int(addresses[0]))+" value="+ addresses[0][0],0,0
	Flip
Wend


Doug Stastny


taxlerendiosk(Posted 2006) [#3]
I might be misunderstanding what you want, but you can cast Ints and pointers to each other.

ArrayOfPointers:Int[100]

(...)

ArrayOfPointers[3] = Int( MyPtr )

(...)

MyPtr = Byte Ptr( ArrayOfPointers[3] )



ImaginaryHuman(Posted 2006) [#4]
There's nothing stopping you having an array of pointers, is there?

Local myarray:Int Ptr[100]

defines an array containing 100 int pointers.

Same for float pointers.

To display them you read the integer at their varptr ie

Print Hex$(Int(VarPtr(myarray[11])[0])) 'or whichever offset

no?


Drey(Posted 2006) [#5]
haha, thanks guy. I was figuring that the complier would have said "this isn't a 2-d array" or something similar. I guess i should just give things a try before i assume they don't work. It's really starting to get to me these days.