devxlogo

Process Local Storage

Process Local Storage

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.

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist