Printing the memory address of a variable

BlitzMax Forums/BlitzMax Beginners Area/Printing the memory address of a variable

byo(Posted 2009) [#1]
Hi, guys.

Is there a way to print the memory address of a variable?
I have a Windows handle and I'd like to retrieve the memory address of that handle as a string.

Is this possible?

Thanks in advance.


ImaginaryHuman(Posted 2009) [#2]
See VarPtr()

e.g. a:Int Ptr=Int Ptr(VarPtr(b))


byo(Posted 2009) [#3]
Thanks for the tip. But now how can I convert from Int Ptr to a String?
I need to print the memory address of a variable like this:

$010c2530



plash(Posted 2009) [#4]
Use the Hex function in brl.retro on the integer value of the pointer? (Note that once you have a string in the "$######" format, trying to convert it to an int will automagically un-hex it.)


Otus(Posted 2009) [#5]
You can just cast the pointer to an integer using Int(VarPtr blah) and then do whatever you want. Like use Hex as Plash stated.


byo(Posted 2009) [#6]
I'll try that.
I was just having problems trying to convert the value to a string. But I guess Hex() will do just fine.

Thank you all.


ImaginaryHuman(Posted 2009) [#7]
Depends how you want to view it. ie

Print Int(VarPtr(a))
Print Hex$(VarPtr(a))
Print Bin$(VarPtr(a))

And by the way, you can do this too:

Local a:Int=0
Local p:Int Ptr=Int Ptr(VarPtr(a))
p[0]=5
Print a 'prints 5