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 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 .



    Comments

    • Bug Fix

      Posted by Legacy on 01/21/2000 12:00am

      Originally posted by: Luiz Kogut

      At first, I'd like to thank you for the code. It was very useful to me.
      I found a bug when you need to allocate more objects than the free size of your buffer. Here is the correction:

      Change the old implementation for the function CWizOneSizeHeap<TYPE, ALLOCATOR>::InitPointers () by this new one...

      template<class TYPE, class ALLOCATOR>
      inline
      void CWizOneSizeHeap<TYPE, ALLOCATOR>::InitPointers ()
      {
      int nStep = m_nStep - 1;
      DATA *p = m_pFirstFree;

      for (int i = 0; i < nStep; i++, p++)
      p->next = p + 1;

      p->next = NULL;
      }

      Reply
    • Where is the ZIP file?

      Posted by Legacy on 11/22/1999 12:00am

      Originally posted by: Danang Suharno

      It would be better if you put all the .h and .cpp files
      to a .ZIP file!!!!

      Thanks

      Reply
    Leave a Comment
    • Your email address will not be published. All fields are required.

    Top White Papers and Webcasts

    • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

    • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

    Most Popular Programming Stories

    More for Developers

    Latest Developer Headlines

    RSS Feeds