Can I get the physical address of a variable or object in C #?

I have to make a project in C # to show how a list works.

I think it's a good idea to show in the GUI:

-in "value" field: node value
- in the "next" field: physical address of the next node

Is it possible?

+3


source to share


1 answer


Yes, with unsafe code (at least a virtual address, not a physical physical memory address, but that's exactly what you want).

Have a look at MSDN: How to Get the Address of a Variable (C # Programming Guide) . It will help you compile the following example (requires /unsafe

unsafe code to be included in project properties or switch ) and what pitfalls might occur when getting the location of movable variables that require the keyword fixed

in the same place basically said.



int number;
int* p = &number; //address-of operator &

      

+3


source







All Articles