BsGlobalFrameAlloc.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Prerequisites/BsPrerequisitesUtil.h"
  4. #include "Allocators/BsGlobalFrameAlloc.h"
  5. #include "Allocators/BsFrameAlloc.h"
  6. namespace bs
  7. {
  8. BS_THREADLOCAL FrameAlloc* _GlobalFrameAlloc = nullptr;
  9. inline BS_UTILITY_EXPORT FrameAlloc& gFrameAlloc()
  10. {
  11. if (_GlobalFrameAlloc == nullptr)
  12. {
  13. // Note: This will leak memory but since it should exist throughout the entirety
  14. // of runtime it should only leak on shutdown when the OS will free it anyway.
  15. _GlobalFrameAlloc = new FrameAlloc();
  16. }
  17. return *_GlobalFrameAlloc;
  18. }
  19. inline BS_UTILITY_EXPORT UINT8* bs_frame_alloc(UINT32 numBytes)
  20. {
  21. return gFrameAlloc().alloc(numBytes);
  22. }
  23. inline BS_UTILITY_EXPORT UINT8* bs_frame_alloc_aligned(UINT32 count, UINT32 align)
  24. {
  25. return gFrameAlloc().allocAligned(count, align);
  26. }
  27. inline BS_UTILITY_EXPORT void bs_frame_free(void* data)
  28. {
  29. gFrameAlloc().dealloc((UINT8*)data);
  30. }
  31. inline BS_UTILITY_EXPORT void bs_frame_free_aligned(void* data)
  32. {
  33. gFrameAlloc().dealloc((UINT8*)data);
  34. }
  35. inline BS_UTILITY_EXPORT void bs_frame_mark()
  36. {
  37. gFrameAlloc().markFrame();
  38. }
  39. inline BS_UTILITY_EXPORT void bs_frame_clear()
  40. {
  41. gFrameAlloc().clear();
  42. }
  43. }