Why Visual Studio memory addresses shuffle based on view?

31 views Asked by At

When viewing memory addresses in Visual Studio, I noticed the arrangement changes depending on how the memory is viewed. Example:

int a = 3;

int* b = &a;

1 byte: 0x 03 00 00 00

2 byte: 0x 0003

4 byte: 0x 00000003

Now with a small number like this, it's not a big deal. But when viewing a larger number...

int a = 1012346589;

int* b = &a;

1 byte: 0x dd 2e 57 3c

2 byte: 0x 2edd 3c57

4 byte: 0x 3c572edd

That is all over the place, and it really trips me up because my intuitive assumption would be this, which is consistent with other tools I've used:

1 byte: 0x 00 00 00 03

2 byte: 0x 0003

4 byte: 0x 00000003

or

1 byte: 0x 3c 57 2e dd

2 byte: 0x 3c57 2edd

4 byte: 0x 3c572edd

I've used other memory debugging tools and this is the first where I've seen it arranged in this way. Is this just a quirk of visual studio, is it a setting?

At first, I thought maybe the 1 byte view was hiding the first 3 bytes because they were 0s, but after testing with larger numbers I found that wasn't the case, and the different views a sometimes produce completely different arrangements.

1

There are 1 answers

0
Node defender On

As Hans Passant said, your processor is little-endian. This is a very basic property of its design and you'd better get used to it.

Please refer to https://en.wikipedia.org/wiki/Endianness