BsMemAllocProfiler.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. namespace BansheeEngine
  3. {
  4. /**
  5. * @brief Specialized allocator for profiler so we can avoid tracking internal profiler memory allocations
  6. * which would skew profiler results.
  7. */
  8. class ProfilerAlloc
  9. {};
  10. /**
  11. * @brief Memory allocator providing a generic implementation.
  12. * Specialize for specific categories as needed.
  13. */
  14. template<>
  15. class MemoryAllocator<ProfilerAlloc> : public MemoryAllocatorBase
  16. {
  17. public:
  18. /**
  19. * @brief Allocates the given number of bytes.
  20. */
  21. static inline void* allocate(size_t bytes)
  22. {
  23. return malloc(bytes);
  24. }
  25. /**
  26. * @brief Allocates the given a number of objects, each of the given number of bytes.
  27. */
  28. static inline void* allocateArray(size_t bytes, UINT32 count)
  29. {
  30. return malloc(bytes * count);
  31. }
  32. /**
  33. * @brief Frees memory previously allocated with "allocate".
  34. */
  35. static inline void free(void* ptr)
  36. {
  37. ::free(ptr);
  38. }
  39. /**
  40. * @brief Frees memory previously allocated with "freeArray". "count" must match the
  41. * original value when array was allocated.
  42. */
  43. static inline void freeArray(void* ptr, UINT32 count)
  44. {
  45. ::free(ptr);
  46. }
  47. };
  48. }