📄 warmemorybuffer.h
字号:
/** Memory organizer for small data blocks that can be freed together. Typically used for file-names, symbol table names and temporary storage. This method does not work for classes. The advantage is that memory allocation is extreemly fast, and that small blocks woun't defragment the main memory. The disadvantage is that individual blocks of memory can't be freed. The memory remains 'used' until the WarMemoryBuffer object is destroyed. Classes that are allocated using this scheme must be derived from WarImplementMemory*/#ifndef WAR_MEMORY_BUFFER_H#define WAR_MEMORY_BUFFER_H/* SYSTEM INCLUDES */#ifndef WAR_LIST_INCLUDED# define WAR_LIST_INCLUDED# include <list>#endif/* PROJECT INCLUDES */#ifndef WAR_TYPES_H# include "WarTypes.h"#endif/* LOCAL INCLUDES *//* FORWARD REFERENCES */#ifdef __cplusplusextern "C" {#endif/****************** BEGIN OLD STYLE C spesific ********//****************** END OLD STYLE C spesific **********/#ifdef __cplusplus }#endif/****************** BEGIN C++ spesific ****************/#ifdef __cplusplustemplate <class T>class WarMemoryBuffer {public: typedef std::list<T *> block_list_t; // LIFECYCLE /// Constructor WarMemoryBuffer(size_t AllocSize = (1024 * 16)); ~WarMemoryBuffer(); // OPERATORS // OPERATIONS /// void Reset(); /** @param Number of T's to get (bytes = Size * sizeof(T) */ T *Malloc(size_t Size); /// T *StrDup(std::basic_string<T>& from); /// Same as the C API function malloc() char *MallocBytes(size_t bytes); // ACCESS // INQUIRY protected:private: void ByteAlign(); inline size_t GetFree() { return mEndOfBlock - mpNextPtr; } void AllocBlock(); war_ccstr_t mEndOfBlock; T *mpNextPtr; size_t mAllocSize; size_t mTotalAllocatedSize; block_list_t mBlocks;};/* INLINE METHODS *//* EXTERNAL REFERENCES *////#define WarMallocStruct(type)\(type *)m_Mem.MallocBytes(sizeof(type))#endif /* __cplusplus *//****************** END C++ spesific ******************/#endif /* WAR_MEMORY_BUFFER_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -