BsMemAllocProfiler.h 1.2 KB

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