Recently, in this question , I asked how to get the raw class memory address in C # (this is a crude unreliable hack and bad practice, do not use it if you do not need it). I succeeded, but then a problem arose: according to this article, the first 2 words in the raw memory representation of the class should be pointers to SyncBlock and RTTI, so the first address of the field should be shifted by 2 words [8 bytes on 32-bit systems, 16 bytes in 64-bit systems] from the very beginning. However, when I delete the first bytes from the memory at the location of the object, the first initial field offset from the object address is only 1 32-bit word (4 bytes), which makes no sense for both types of systems. From the question I linked:
class Program {
Why is that? Maybe I just misunderstood the address, but how and why? And if I do not, what could be wrong? Maybe if this article is wrong, I just misunderstood what the title of a managed class looks like? Or maybe it doesn't have a Lock pointer - but why and how is this possible? ..
(These are obviously just a few possible options, and although I still carefully check each one that I can predict, wild guesses cannot compare both time and accuracy with the correct answer.)
source share