Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There's a fundamental flaw in the approach, based on a possible misunderstanding what a <em>pointer</em> really means. A pointer, IntPtr in managed code, is simply the address of a location in memory. You read what is pointed-to with the kind of code you already use, like Marshal.PtrToStructure().</p> <p>A problem with pointers is that they are only valid in one process. Every process has its own virtual memory address space. With an additional restriction in managed code, the garbage collector can randomly move an object from one location to another. There are workarounds for that, you could pinvoke ReadProcessMemory() to read data from another process. And you work around the garbage collector behavior by <em>pinning</em> an object, GCHandle.Alloc()</p> <p>But these are workarounds that don't belong in a custom serialization scheme. An obvious failure mode for ReadProcessMemory() is just not knowing which process has the data. Or not having sufficient rights to use it. Or the process running on another machine. Pinning pointers is flawed because there is no good guarantee that you'll ever un-pin them.</p> <p>So any serialization approach solves this problem by flattening the data, eliminating pointers by replacing them with the pointed-to data. And resurrect the object graph in the deserializer. The job done by classes like BinaryFormatter, XmlSerializer, DataContractSerializer and DataContractJsonSerializer. And 3rd party ones like Mark's favorite. Don't write your own, there are so many of them because it is hard to get right.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload