2

I have the following simple test code:

List<byte> test = new List<byte>();
for (int i = 0; i <= 0xFF; i++)
{
    test.Add((byte)i);
}
byte[] testAsArray = test.ToArray();

I break after that last line. In the locals window in Visual Studio the array testAsArray starts as I would expect with testAsArray[0] equal to 0x00. But when I open Visual Studio's memory window and type testArray into the address box this is what I see:

vs memory window screenshot

Before the start of the expected byte sequence I have eight other bytes, i.e. the memory in the location testArray starts

30 72 12 04 00 01 00 00
00 01 02 03 04 05 06 07
08 09 0a 0b 0c 0d 0e 0f

What are the leading eight bytes? What expression would I need to type into the memory window's address box to go directly to the head of the actual byte array?

5
  • 1
    Maybe this might help: codeproject.com/Articles/3467/Arrays-UNDOCUMENTED Commented Jan 11, 2019 at 10:55
  • Do you really want to dive into implementation details? What you was trying to do when you opened Memory window? Why? If you would really want to know what you are asking the question would be different. Commented Jan 11, 2019 at 11:24
  • I want to know is how to look at a byte[] in the memory window. Will I always have to skip 8 bytes or does that implementation overhead differ in length with different byte arrays? I'm debugging some web socket code that's failing to parse and so am spending a lot of time staring at the beginnings and ends of byte arrays. Commented Jan 11, 2019 at 11:27
  • Why do you look into "Memory" window for this? Why not observing array values in Watch, Local or even Auto window? You can right click and choose " display as hexadecimal" there if that is the problem. Commented Jan 11, 2019 at 11:31
  • @Sinatr so I can scan large blocks of bytes easily. Commented Jan 11, 2019 at 11:33

1 Answer 1

2

your example is from a 32 bit system?

what you see are:

  • 4 bytes for Object Header Word and
  • 4 bytes for Method Table Pointer

On a 64-bit system, a word/pointer is 8 bytes instead of 4 and are aligned to 8-byte "grids"

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. If I change the build target to x64 there are indeed 16 bytes before the byte array starts. So I can reliably discount the first 8 for x86 builds and the first 16 for x64 builds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.