1.2.2 Private Heaps and Locality

Private heaps increase locality. Locality (spatial locality in this case) is the beneficial property of data accessed close together in time being situated close together in memory. High locality results in fewer expensive page faults and cache misses, since the next datum to be accessed is more likely to be stored on the same page of RAM or in the same cache line. Locality is one of the main determinants of overall performance for heavyweight applications which use more memory than there is available RAM. The data in a private heap (say a linked list of C++ objects) are likely to be intensively accessed when the owning thread has the processor or a routine of the owning DLL is called. These data will be closer in memory than if scattered about a large heap used by many DLLs and threads.

The contention and locality advantages of private heaps are limited under NT, because any Windows Application Programming Interface (API) routine invoked will not allocate from the private heap, rather from a shared heap created at the inception of the process called the process heap (a term widely used though something of a misnomer). Also, any nested call to another DLL will access data held not on the private heap but on the process heap or a distinct private heap owned by the called DLL.