Printing the memory address of a variable
BlitzMax Forums/BlitzMax Beginners Area/Printing the memory address of a variable
| ||
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. |
| ||
See VarPtr() e.g. a:Int Ptr=Int Ptr(VarPtr(b)) |
| ||
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 |
| ||
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.) |
| ||
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. |
| ||
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. |
| ||
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 |