wxArt2D
a2dmemmgr.h
Go to the documentation of this file.
1 /*! \file wx/general/a2dmemmgr.h
2  \brief memory management which can optionally be used for certain intensively used classes.
3  \author Leo kadisoff
4  \author Klaas Holwerda
5  \date Created 05/25/2005
6 
7  Copyright: 2003-2005 (c) Klaas Holwerda
8 
9  Licence: wxWidgets Licence
10 
11  RCS-ID: $Id: a2dmemmgr.h,v 1.7 2007/07/30 19:34:11 titato Exp $
12 */
13 
14 #ifndef __A2DMEMMGR_H__
15 #define __A2DMEMMGR_H__
16 
17 #include <wx/general/smrtptr.h>
18 
19 //! Simple Memory manager for some objects which often create and destroy to replace OS-system calls.
20 class A2DGENERALDLLEXP a2dMemManager
21 {
22 private:
23  //! a list of freed memory blocks
24  struct a2dFreeList
25  {
26  //! a next list of freed blocks another blockSize
27  a2dFreeList* m_next;
28  //! a top of current list of freed memory blocks by this blockSize
29  void* m_topOfList;
30  //! a current blocksize for list with top m_topOfList
31  size_t m_blockSize;
32 
33  //! a count of freed blocks in this list
34  int m_count;
35 
36  //! constructor
37  a2dFreeList( a2dFreeList* next, size_t blockSize )
38  : m_next( next ),
39  m_topOfList( NULL ),
40  m_blockSize( blockSize ),
41  m_count( 0 )
42  {
43  }
44  };
45  //! pointer to a first list of freed blocks
46  a2dFreeList* m_allLists;
47  //! count of lists of freed blocks
48  int m_count;
49  //! a name of memory manager for debugging
50  const wxChar* m_mgrname;
51 
52 // wxCriticalSection m_guard;
53 
54 public:
55  //! contructor of memory manager
56  a2dMemManager( const wxChar* mgrname ) : m_allLists( NULL ), m_count( 0 ), m_mgrname( mgrname )
57  {
58  }
59  //! destructor of memory manager
60  /*!
61  Destroing all lists of freed memory blocks which were allocated in Allocate() by OS-system allocation calls
62  */
63  ~a2dMemManager();
64 
65  //! function for allocating memory block by size bytes
66  /*!
67  Returns pointer to freed block if exists in lists or calls OS-system function for allocating memory block
68  */
69  void* Allocate( size_t bytes );
70  //! function for adding memory block by size bytes to list of freed memory blocks
71  /*
72  This function doesn't free to OS-system memory block by pointer 'space'.
73  It adds memory block by pointer 'space' to internal lists.
74  It is speed up.
75  */
76  void Deallocate( void* space, size_t bytes );
77 };
78 
79 #ifdef __WXDEBUG__
80 #if wxUSE_STACKWALKER
81 extern A2DGENERALDLLEXP wxString a2dGetStackTrace( size_t skip = 1, bool withArgs = false, int maxCalls = 30, int maxLines = 20 );
82 #endif
83 #endif
84 #endif // __A2DMEMMGR_H__
Simple Memory manager for some objects which often create and destroy to replace OS-system calls...
Definition: a2dmemmgr.h:20
a2dMemManager(const wxChar *mgrname)
contructor of memory manager
Definition: a2dmemmgr.h:56
smart pointer class and list.
a2dmemmgr.h Source File -- Sun Oct 12 2014 17:04:12 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation