00001 /*! \file wx/general/a2dmemmgr.h 00002 \brief memory management which can optionally be used for certain intensively used classes. 00003 \author Leo kadisoff 00004 \author Klaas Holwerda 00005 \date Created 05/25/2005 00006 00007 Copyright: 2003-2005 (c) Klaas Holwerda 00008 00009 Licence: wxWidgets Licence 00010 00011 RCS-ID: $Id: a2dmemmgr.h,v 1.7 2007/07/30 19:34:11 titato Exp $ 00012 */ 00013 00014 #ifndef __A2DMEMMGR_H__ 00015 #define __A2DMEMMGR_H__ 00016 00017 #include <wx/general/smrtptr.h> 00018 00019 //! Simple Memory manager for some objects which often create and destroy to replace OS-system calls. 00020 class A2DGENERALDLLEXP a2dMemManager 00021 { 00022 private: 00023 //! a list of freed memory blocks 00024 struct a2dFreeList 00025 { 00026 //! a next list of freed blocks another blockSize 00027 a2dFreeList* m_next; 00028 //! a top of current list of freed memory blocks by this blockSize 00029 void* m_topOfList; 00030 //! a current blocksize for list with top m_topOfList 00031 size_t m_blockSize; 00032 00033 //! a count of freed blocks in this list 00034 int m_count; 00035 00036 //! constructor 00037 a2dFreeList(a2dFreeList* next, size_t blockSize) 00038 : m_next(next), 00039 m_topOfList(NULL), 00040 m_blockSize(blockSize), 00041 m_count(0) 00042 { 00043 } 00044 }; 00045 //! pointer to a first list of freed blocks 00046 a2dFreeList* m_allLists; 00047 //! count of lists of freed blocks 00048 int m_count; 00049 //! a name of memory manager for debugging 00050 const wxChar* m_mgrname; 00051 00052 // wxCriticalSection m_guard; 00053 00054 public: 00055 //! contructor of memory manager 00056 a2dMemManager(const wxChar *mgrname) : m_allLists(NULL), m_count(0), m_mgrname(mgrname) 00057 { 00058 } 00059 //! destructor of memory manager 00060 /*! 00061 Destroing all lists of freed memory blocks which were allocated in Allocate() by OS-system allocation calls 00062 */ 00063 ~a2dMemManager(); 00064 00065 //! function for allocating memory block by size bytes 00066 /*! 00067 Returns pointer to freed block if exists in lists or calls OS-system function for allocating memory block 00068 */ 00069 void* Allocate(size_t bytes); 00070 //! function for adding memory block by size bytes to list of freed memory blocks 00071 /* 00072 This function doesn't free to OS-system memory block by pointer 'space'. 00073 It adds memory block by pointer 'space' to internal lists. 00074 It is speed up. 00075 */ 00076 void Deallocate(void* space, size_t bytes); 00077 }; 00078 00079 #ifdef __WXDEBUG__ 00080 #if wxUSE_STACKWALKER 00081 extern A2DGENERALDLLEXP wxString a2dGetStackTrace(size_t skip = 1, bool withArgs = false, int maxCalls = 30, int maxLines = 20); 00082 #endif 00083 #endif 00084 #endif // __A2DMEMMGR_H__