Memory API Wrappers | CodeGuru

Memory API Wrappers

. You can also find this and other articles at his web site at http://www.wizsoft.com/~poul/srs/ One size private heap class CWizOneSizeHeap. I wrote this class for very common situation: when you have to allocate many of small objects of the same size; the obvious case is some class widely used in a program. The assumption that […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 6, 1998
3 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

. You can also
find this and other articles at his web site at http://www.wizsoft.com/~poul/srs/

  • One size private heap class CWizOneSizeHeap.
    I wrote this class for very common situation: when you have to allocate
    many of small objects of the same size; the obvious case is some class widely used in a
    program. The assumption that all objects on the heap are of the same size allows to
    minimize allocation overhead to zero. Indeed, every allocation block in the regular
    heap is preceded by block size. But when the size is known in advance, you could save this
    place. The technique is simple: the heap manager requests big blocks of the memory
    from some common heap. Every block of memory is either occupied by allocated
    object, or points to the next free block. Therefore it manages "in place" linked
    list of free items without any overhead. The sources are here.

    NB: Feel free to remove inlines if you’re more concerned about size
    then about speed.
     
  • Local heap class CWizLocalHeap – wrapper for Win32 API
    local heap machinery.

    Helper class CWizLocalHeapLock useful for locking the heap in the
    multithreading environment.

    Files LOCALHEP.H and LOCALHEP.CPP
    .
  • Template class CWizTypedLocalHeap derived from CWizLocalHeap to
    avoid mess with local heap parameters.

    Class CWizDefaultTypedLocalHeap
    derived from CWizTypedLocalHeap and supplies reasonable default parameters.

    Define DECLARE_LOCAL_HEAP forces objects of any class to be
    allocated from it’s own private local heap. Very useful in new-intensive
    algorithms.

    Files TypedLocalHeap.CPP and TypedLocalHeap.H
    .
  • Virtual memory class CWizVirtualMemory
    – wrapper for Win32 API virtual memory machinery.

    Derived template class CWizTypedVMem to be used as virtual array.
    Files VIRT_MEM.H and VIRT_MEM.CPP
    .
  • Memory mapped file wrappers:
    • CWizFileMapping – kind of file mapping wrapper.
    • CWizFileMapView – view of this mapping (actual memory
      address).
    • template <class TYPE> class CWizFileView – kind of "virtual array"
      mirroring a file.
    • template <class TYPE> class CWizROFileView – read-only view (virtual array) of an
      existing file.
    • CWizFullFileView – read/write file mapping. Uses CWizTempFileStrategy for managing
      temporary files.
    • template <class TYPE> class CWizTypedFullFileView – typed derivative of
      CWizFullFileView.

    Files FILE_MAP.H and FILE_MAP.CPP
    .

    • CWizFileROFileMapping – implements
      "windowed" view to memory mapping.Useful when address space is low or when
      access to the file is rare.
      Nested class Window acts like actual window to the mapping and moves itself by demand.
      This class has template parameter LOCKER which implements multithreading synchronization
      for Window objects. Two classes supplied for this:
    • CWizFileMapNoLocker – no locking and synchronization. Useful when:

      a) only
      single thread accesses the view or
      b) another synchronization implemented in your application or
      c) you are absolutely sure it’s no need for synchronization.

    • CWizFileMapCritSectLocker – uses critical section for synchronization between
      threads.

      Please note that synchronization is managed only when retrieving
      the view from memory mapping. Every view supposed to be thread-specific or at protected by
      another way.

    • template<class LOCKER, class DATA> class CWizTypedFileROFileMapping –
      typed derivative of CWizFileROFileMapping (like virtual array of structs).
      Because of strange compilation errors -:) the nested class is called Wnd instead of
      Window.

    Files FileMapWindow.H and FileMapWindow.CPP .

    CodeGuru Logo

    CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

    Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

    Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.