Buffers.h 1016 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /***********************************************************************/
  2. //文 件 名:CBuffers.h
  3. //功 能:CBuffers类声明
  4. // CBuffers类是一个利用内存池机制来分配内存的工具类
  5. /***********************************************************************/
  6. #ifndef __CBuffers__
  7. #define __CBuffers__
  8. class CBuffers
  9. {
  10. public:
  11. char* GetBuf(size_t lsize);
  12. char* Extern(size_t maxSize);
  13. char* Copy( void * lpData, size_t lsize );
  14. char* Append( void * lpData, size_t lsize );
  15. void Attach( CBuffers*pMemory );
  16. void Detach();
  17. void Release(void);
  18. inline operator const char * (void) const;
  19. const CBuffers& operator=(const char * lpString);
  20. const CBuffers& operator+=(const char * lpString);
  21. //绑定地址:自动释放
  22. CBuffers(void * lpBuffer=0);
  23. ~CBuffers(void);
  24. size_t sizeData,sizeMalloc;
  25. char *bufData;
  26. };
  27. #define FREE_BUFFER( x ) \
  28. { \
  29. CBuffers buf( x ); \
  30. }
  31. #define INIT_BUFFER( x, n ) \
  32. { \
  33. CBuffers buf; \
  34. x = buf.GetBuf( ( n ) ); \
  35. buf.Detach(); \
  36. }
  37. #endif //__CBuffers__