title: Shared memory in DLLs
body: <p>How does sharing memory works in DLLs? </p>
  
  <p>When DLL is attached to process, it uses the same memory addresses as process. Let's assume we have following function in DLL:</p>
  
  <pre><code>int * data = 0;
  int foo()
  {
      if (!data) data = new int(random());
      return *data;
  }
  </code></pre>
  
  <p>When process A calls this function it creates new object (int) and returns its value.
  But now process B attaches this DLL. It calls foo() but I don't understand how would it work, because <code>data</code> is in process' A memory space. How would B be able to directly use it?</p>