BsGlobalFrameAlloc.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsPrerequisitesUtil.h"
  4. #include "BsGlobalFrameAlloc.h"
  5. #include "BsFrameAlloc.h"
  6. namespace BansheeEngine
  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 void bs_frame_free(void* data)
  24. {
  25. gFrameAlloc().dealloc(data);
  26. }
  27. inline BS_UTILITY_EXPORT void bs_frame_mark()
  28. {
  29. gFrameAlloc().markFrame();
  30. }
  31. inline BS_UTILITY_EXPORT void bs_frame_clear()
  32. {
  33. gFrameAlloc().clear();
  34. }
  35. }