Browse Source

Stack allocator is now inline

Florian Born 3 years ago
parent
commit
7f0509ae87
3 changed files with 11 additions and 9 deletions
  1. 1 1
      code/CMakeLists.txt
  2. 6 4
      code/Common/StackAllocator.h
  3. 4 4
      code/Common/StackAllocator.inl

+ 1 - 1
code/CMakeLists.txt

@@ -194,7 +194,7 @@ SET( Common_SRCS
   Common/ScenePreprocessor.h
   Common/SkeletonMeshBuilder.cpp
   Common/StackAllocator.h
-  Common/StackAllocator.cpp
+  Common/StackAllocator.inl
   Common/StandardShapes.cpp
   Common/TargetAnimation.cpp
   Common/TargetAnimation.h

+ 6 - 4
code/Common/StackAllocator.h

@@ -64,9 +64,9 @@ namespace Assimp
 class StackAllocator {
 public:
     // Constructs the allocator
-    StackAllocator();
+    inline StackAllocator();
     // Destructs the allocator and frees all memory
-    ~StackAllocator();
+    inline ~StackAllocator();
 
     // non copyable
     StackAllocator(const StackAllocator &) = delete;
@@ -74,11 +74,11 @@ public:
 
     // Returns a pointer to byteSize bytes of heap memory that persists
     // for the lifetime of the allocator (or until FreeAll is called).
-    void *Allocate(size_t byteSize);
+    inline void *Allocate(size_t byteSize);
 
     // Releases all the memory owned by this allocator.
     // Memory provided through function Allocate is not valid anymore after this function has been called.
-    void FreeAll();
+    inline void FreeAll();
 
 private:
     constexpr const static size_t g_maxBytesPerBlock = 64 * 1024 * 1024; // The maximum size (in bytes) of a block
@@ -91,4 +91,6 @@ private:
 
 } // namespace Assimp
 
+#include "StackAllocator.inl"
+
 #endif // include guard

+ 4 - 4
code/Common/StackAllocator.cpp → code/Common/StackAllocator.inl

@@ -46,14 +46,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 using namespace Assimp;
 
 
-StackAllocator::StackAllocator() {
+inline StackAllocator::StackAllocator() {
 }
 
-StackAllocator::~StackAllocator() {
+inline StackAllocator::~StackAllocator() {
     FreeAll();
 }
 
-void *StackAllocator::Allocate(size_t byteSize) {
+inline void *StackAllocator::Allocate(size_t byteSize) {
     if (m_subIndex + byteSize > m_blockAllocationSize) // start a new block
     {
         // double block size every time, up to maximum of g_maxBytesPerBlock.
@@ -72,7 +72,7 @@ void *StackAllocator::Allocate(size_t byteSize) {
     return data;
 }
 
-void StackAllocator::FreeAll() {
+inline void StackAllocator::FreeAll() {
     for (size_t i = 0; i < m_storageBlocks.size(); i++) {
         delete [] m_storageBlocks[i];
     }