Address of a variable: Difference between revisions
Content deleted Content added
Added Visual Basic |
|||
Line 170: | Line 170: | ||
hex abcdef is-data foo |
hex abcdef is-data foo |
||
foo . |
foo . |
||
=={{header|Visual Basic .NET}}== |
|||
Visual Basic uses managed memory that can be moved around at any time. If a memory address for a variable is needed, the address is created first and then its contents copied. |
|||
===Get the Address=== |
|||
Allocates a stable address in unmanaged memory, copies a variable to it, then returns the address itself. |
|||
Dim x = 5 |
|||
Dim ptrX As IntPtr |
|||
ptrX = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Integer))) |
|||
Marshal.StructureToPtr(5, ptrX, False) |
|||
Dim addressX = ptrX.ToInt64 |
|||
===Set the Address=== |
|||
Sets the pointer to the address A100 in hex. |
|||
Dim ptrX As New IntPtr(&HA100) |