2
0

BsGlobalFrameAlloc.cpp 887 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "BsPrerequisitesUtil.h"
  2. #include "BsGlobalFrameAlloc.h"
  3. #include "BsFrameAlloc.h"
  4. namespace BansheeEngine
  5. {
  6. BS_THREADLOCAL FrameAlloc* _GlobalFrameAlloc = nullptr;
  7. inline BS_UTILITY_EXPORT FrameAlloc& gFrameAlloc()
  8. {
  9. if (_GlobalFrameAlloc == nullptr)
  10. {
  11. // Note: This will leak memory but since it should exist throughout the entirety
  12. // of runtime it should only leak on shutdown when the OS will free it anyway.
  13. _GlobalFrameAlloc = new FrameAlloc();
  14. }
  15. return *_GlobalFrameAlloc;
  16. }
  17. inline BS_UTILITY_EXPORT UINT8* bs_frame_alloc(UINT32 numBytes)
  18. {
  19. return gFrameAlloc().alloc(numBytes);
  20. }
  21. inline BS_UTILITY_EXPORT void bs_frame_free(void* data)
  22. {
  23. gFrameAlloc().dealloc(data);
  24. }
  25. inline BS_UTILITY_EXPORT void bs_frame_mark()
  26. {
  27. gFrameAlloc().markFrame();
  28. }
  29. inline BS_UTILITY_EXPORT void bs_frame_clear()
  30. {
  31. gFrameAlloc().clear();
  32. }
  33. }