Writing out memory addresses 
Author Message
 Writing out memory addresses

Is there any way to actually have a look at the actual memory addresses of say an integer?

For example, write it out to the console?

I wanna do something like "Console.WriteLine(&A);"

--
Magnus Lindberg
cshrp.net - Elegant code by witty programmers

*** Sent via Developersdex http://www.*-*-*.com/ ***
Don't just participate in USENET...get rewarded for it!



Mon, 01 Mar 2004 22:35:22 GMT  
 Writing out memory addresses


Quote:
> Is there any way to actually have a look at the actual memory addresses of say an integer?

> For example, write it out to the console?

> I wanna do something like "Console.WriteLine(&A);"

Even if there was, it could change right after you print it out -- due
to garbage collection.  Why do you need the address?

--
Patrick Steele



Mon, 01 Mar 2004 23:14:55 GMT  
 Writing out memory addresses
Well, isn't it so that code in unsafe blocks aren't garbage collected?
And there is a fixed statement for pinning stuff so they don't get moved around.

I want to look at the addresses mostly out of curiosity. I want to know at what address my stack starts and so on.

Cheers,

--
Magnus Lindberg
cshrp.net - Elegant code by witty programmers

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Tue, 02 Mar 2004 15:35:19 GMT  
 Writing out memory addresses
Tools like cordbg are made for this.
Quote:

> Well, isn't it so that code in unsafe blocks aren't garbage collected?
> And there is a fixed statement for pinning stuff so they don't get moved around.

> I want to look at the addresses mostly out of curiosity. I want to know at what address my stack starts and so on.

> Cheers,

> --
> Magnus Lindberg
> cshrp.net - Elegant code by witty programmers

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Tue, 02 Mar 2004 16:00:51 GMT  
 Writing out memory addresses
Still, I wanna do something similar in C# just for the fun of it. Are you guys telling me it can't be done?

--
Magnus Lindberg
cshrp.net - Elegant code by witty programmers

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Tue, 02 Mar 2004 16:19:11 GMT  
 Writing out memory addresses
as you wrote, 'unsafe' and 'fixed' are the keywords!

(Must set the "allow unsafe code blocks" option
in C# Project "Build Configuration Properties")

Read all in MSDN about unsafe, fixed
and moveable variables!

public static unsafe void UsingUnsafe()
 {
 int int1var = 1;
 int int2var = 2;
 int* int1ptr = &int1var;
 int* int2ptr = &int2var;
 Console.WriteLine( "Address of int1var={0:x}, int2var={1:x}",
                     (int) int1ptr, (int) int2ptr );
 *int1ptr = 11;
 *int2ptr = 22;

int[] intarr = new int[3];
intarr[0] = 111;
intarr[1] = 222;
intarr[2] = 333;
fixed( int* arrptr = intarr )
 {
 Console.WriteLine( "Address of intarr={0:x}",
                    (int) arrptr );
 }

Quote:
}

 NETMaster
 http://www.cetus-links.org/oo_csharp.html

I've been "encouraged" to share this helpful information from my lawyers:
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.
? 2001 NETMaster. All rights reserved.

Quote:

> Still, I wanna do something similar in C# just for the fun of it. Are you guys telling me it can't be done?

> --



Tue, 02 Mar 2004 17:08:03 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Obtaining physical memory address from virtual memory address?

2. writing a DLL to read a device located at a specific PC memory address

3. Writing to a Memory Address

4. Checksums of a.outs

5. Colour print outs of source code ?

6. reading and writing to a port address using Visual C++

7. Write to an absolute address

8. Writing to port address 0x21

9. read/write from /to IO address

10. writing a value to specified address

11. Write to an address

12. Write address from ie to text file

 

 
Powered by phpBB® Forum Software