OgrePortMemory.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. // TODO PORT - I define the memory allocation here because they're often used but I don't have an implementation for them. I should remove calls to the macros altogether but this will do for now
  3. #include <malloc.h>
  4. #include "OgreAlignedAllocator.h"
  5. #define OGRE_NEW new
  6. #define OGRE_DELETE delete
  7. #define OGRE_MALLOC(bytes, category) malloc(bytes)
  8. #define OGRE_ALLOC_T(T, count, category) static_cast<T*>(malloc(sizeof(T)*(count)))
  9. #define OGRE_FREE(ptr, category) free((void*)ptr)
  10. #define OGRE_NEW_T(T, category) new T
  11. #define OGRE_NEW_ARRAY_T(T, count, category) new T[count]
  12. #define OGRE_DELETE_T(ptr, T, category) if(ptr){delete ptr;}
  13. #define OGRE_DELETE_ARRAY_T(ptr, T, count, category) if(ptr){delete[] ptr;}
  14. namespace Ogre
  15. {
  16. template<typename T>
  17. T* constructN(T* basePtr, size_t count)
  18. {
  19. for (size_t i = 0; i < count; ++i)
  20. {
  21. new ((void*)(basePtr+i)) T();
  22. }
  23. return basePtr;
  24. }
  25. }
  26. #define OGRE_MALLOC_SIMD(bytes, category) ::Ogre::AlignedMemory::allocate(bytes)
  27. #define OGRE_MALLOC_ALIGN(bytes, category, align) ::Ogre::AlignedMemory::allocate(bytes, align)
  28. #define OGRE_ALLOC_T_SIMD(T, count, category) static_cast<T*>(::Ogre::AlignedMemory::allocate(sizeof(T)*(count),OGRE_SIMD_ALIGNMENT))
  29. #define OGRE_ALLOC_T_ALIGN(T, count, category, align) static_cast<T*>(::Ogre::AlignedMemory::allocate(sizeof(T)*(count), align))
  30. #define OGRE_FREE_SIMD(ptr, category) ::Ogre::AlignedMemory::deallocate(ptr)
  31. #define OGRE_FREE_ALIGN(ptr, category, align) ::Ogre::AlignedMemory::deallocate(ptr)
  32. //
  33. #define OGRE_NEW_T_SIMD(T, category) new (::Ogre::AlignedMemory::allocate(sizeof(T))) T
  34. #define OGRE_NEW_ARRAY_T_SIMD(T, count, category) ::Ogre::constructN(static_cast<T*>(::Ogre::AlignedMemory::allocate(sizeof(T)*(count))), count)
  35. #define OGRE_DELETE_T_SIMD(ptr, T, category) if(ptr){(ptr)->~T(); ::Ogre::AlignedMemory::deallocate(ptr);}
  36. #define OGRE_DELETE_ARRAY_T_SIMD(ptr, T, count, category) if(ptr){for (size_t b = 0; b < count; ++b) { (ptr)[b].~T();} ::Ogre::AlignedMemory::deallocate(ptr);}
  37. #define OGRE_NEW_T_ALIGN(T, category, align) new (::Ogre::AlignedMemory::allocate(sizeof(T), align)) T
  38. #define OGRE_NEW_ARRAY_T_ALIGN(T, count, category, align) ::Ogre::constructN(static_cast<T*>(::Ogre::AlignedMemory::allocate(sizeof(T)*(count), align)), count)
  39. #define OGRE_DELETE_T_ALIGN(ptr, T, category, align) if(ptr){(ptr)->~T(); ::Ogre::AlignedMemory::deallocate(ptr);}
  40. #define OGRE_DELETE_ARRAY_T_ALIGN(ptr, T, count, category, align) if(ptr){for (size_t _b = 0; _b < count; ++_b) { (ptr)[_b].~T();} ::Ogre::AlignedMemory::deallocate(ptr);}
  41. namespace Ogre
  42. {
  43. enum MemoryCategory
  44. {
  45. /// General purpose
  46. MEMCATEGORY_GENERAL = 0,
  47. /// Geometry held in main memory
  48. MEMCATEGORY_GEOMETRY = 1,
  49. /// Animation data like tracks, bone matrices
  50. MEMCATEGORY_ANIMATION = 2,
  51. /// Nodes, control data
  52. MEMCATEGORY_SCENE_CONTROL = 3,
  53. /// Scene object instances
  54. MEMCATEGORY_SCENE_OBJECTS = 4,
  55. /// Other resources
  56. MEMCATEGORY_RESOURCE = 5,
  57. /// Scripting
  58. MEMCATEGORY_SCRIPTING = 6,
  59. /// Rendersystem structures
  60. MEMCATEGORY_RENDERSYS = 7,
  61. // sentinel value, do not use
  62. MEMCATEGORY_COUNT = 8
  63. };
  64. /** @} */
  65. /** @} */
  66. }