How to see how a C # array is stored in memory?

I would like to see how a C # array fits into computer memory.

What I would like to see are basically two columns with addresses, second with array elements. Is it possible?

I would like to start with a 1D array, but then I would like to watch how multidimensional arrays are laid.

Question

How can I see this through VisualStudio?

+6
source share
2 answers

You can use the Visual Studio debugger to view the layout of the array. A simple example:

static void Main(string[] args) { int[] arr = { 1, 2, 3 }; Console.ReadLine(); // Breakpoint here } 

Use Project + Properties, Build tab, Target target = x86. Set a breakpoint on the specified line, press F5 when it enters Debug + Windows + Memory + Memory 1. Enter arr in the Address field. Right-click on the window and select "4 byte integer." Looks like that:

enter image description here

The first word is "type descriptor", its value is random, just ignore it. You can no doubt guess the rest, you will see the Length array and the elements of the array.

+14
source

You can use WinDbg with sos or psscor extensions.

0
source

Source: https://habr.com/ru/post/983229/


All Articles