DS_BytePool.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. /// \file DS_BytePool.h
  11. ///
  12. #ifndef __BYTE_POOL_H
  13. #define __BYTE_POOL_H
  14. #include "RakMemoryOverride.h"
  15. #include "DS_MemoryPool.h"
  16. #include "Export.h"
  17. #include "SimpleMutex.h"
  18. #include "RakAssert.h"
  19. // #define _DISABLE_BYTE_POOL
  20. // #define _THREADSAFE_BYTE_POOL
  21. namespace DataStructures
  22. {
  23. // Allocate some number of bytes from pools. Uses the heap if necessary.
  24. class RAK_DLL_EXPORT BytePool
  25. {
  26. public:
  27. BytePool();
  28. ~BytePool();
  29. // Should be at least 8 times bigger than 8192
  30. void SetPageSize(int size);
  31. unsigned char* Allocate(int bytesWanted, const char *file, unsigned int line);
  32. void Release(unsigned char *data, const char *file, unsigned int line);
  33. void Clear(const char *file, unsigned int line);
  34. protected:
  35. MemoryPool<unsigned char[128]> pool128;
  36. MemoryPool<unsigned char[512]> pool512;
  37. MemoryPool<unsigned char[2048]> pool2048;
  38. MemoryPool<unsigned char[8192]> pool8192;
  39. #ifdef _THREADSAFE_BYTE_POOL
  40. SimpleMutex mutex128;
  41. SimpleMutex mutex512;
  42. SimpleMutex mutex2048;
  43. SimpleMutex mutex8192;
  44. #endif
  45. };
  46. }
  47. #endif
粤ICP备19079148号