Question:
Is there a way to get memory allocated that is global to the current process? Thread local storage won’t do the trick because you need a global handle to access it. My problem is that I need some memory that any thread in the process can access, but that can’t be accessed by other processes/instances of the same application. The memory needs to be accessed from the main program and from several DLLs.
Answer:
If you are working with 32-bit Windows, you can simply allocate global memory and it should be available to all threads running within that process. In addition, it would not be available to other processes because 32-bit Windows runs each process in its own address space.
If you are going directly to the API, newer applications can manage memory using the HeapAlloc, HeapReAlloc, HeapFree, and HeapSize functions. These are all specific to the running process.
The GetProcessHeap function obtains a handle to the heap of the calling process.