[Python-Dev] Windows and PyObject_NEW

Gordon McMillan gmcm@hypernet.com
Sat, 25 Mar 2000 10:46:01 -0500

Vladimir Marangozov

> ... And I believe that the memory allocated
> by the core DLL is accessible from the other DLL's of the process.
> (I haven't seen evidence on the opposite, but tell me if this is not true)

This is true. Or, I should say, it all boils down to 
 HeapAlloc( heap, flags, bytes)
and malloc is going to use the _crtheap.

> In the beginning of Chapter 9, Heaps, I read the following:
> """
> ...About Win32 heaps (compared to Win16 heaps)...
> * There is only one kind of heap (it doesn't have any particular name,
>   like "local" or "global" on Win16, because it's unique)
> * Heaps are always local to a process. The contents of a process heap is
>   not accessible from the threads of another process. A large number of
>   Win16 applications use the global heap as a way of sharing data between
>   processes; this change in the Win32 heaps is often a source of problems
>   for porting Win16 applications to Win32.
> * One process can create several heaps in its addressing space and can
>   manipulate them all.
> * A DLL does not have its own heap. It uses the heaps as part of the
>   addressing space of the process. However, a DLL can create a heap in
>   the addressing space of a process and reserve it for its own use.
>   Since several 16-bit DLLs share data between processes by using the
>   local heap of a DLL, this change is a source of problems when porting
>   Win16 apps to Win32...
> """
> This last paragraph confuses me. On one hand, it's stated that all heaps
> can be manipulated by the process, and OTOH, a DLL can reserve a heap for
> personal use within that process (implying the heap is r/w protected for
> the other DLLs ?!?). 

At any time, you can creat a new Heap
 handle HeapCreate(options, initsize, maxsize)

Nothing special about the "dll" context here. On Win9x, only 
someone who knows about the handle can manipulate the 
heap. (On NT, you can enumerate the handles in the process.)

I doubt very much that you would break anybody's code by 
removing the Windows specific behavior.

But it seems to me that unless Python always uses the 
default malloc, those of us who write C++ extensions will have 
to override operator new? I'm not sure. I've used placement 
new to allocate objects in a memory mapped file, but I've never 
tried to muck with the global memory policy of C++ program.

- Gordon