Suppose there is an array of bytes
byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; and such
[StructLayout(LayoutKind.Explicit)] struct ByteToUlongConverter { [FieldOffset(0)] public byte[] bytes; [FieldOffset(0)] public ulong[] ulongs; public ByteToUlongConverter(byte[] bytes) { this.ulongs = null; this.bytes = bytes; } } structure.
Next, using this structure, I do
ByteToUlongConverter conv = new ByteToUlongConverter(bytes); foreach (ulong ul in conv.ulongs) Console.WriteLine($"{ul:X16}"); This displays something like
0807060504030201 793C086C00000000 0000000000000000 0000000000000000 0000000000000000 0000000004710B40 00000001793BFDD8 793BED0C00000000 Those. I allocated 8 bytes, and read 64 (you can not only read, but write something).
These extra bytes are they whose? What is this memory? Those. as far as I understand my array is somewhere in the heap, and this is something that lies nearby. A heap in .Net as organized, is it one for all processes or does each process have its own heap? Those. Can another process, without special privileges, try to consider something in my process in this way?