Stack allocator is now inline

pull/4494/head
Florian Born 2022-04-21 11:33:04 +02:00
parent 0355ae967f
commit 7f0509ae87
3 changed files with 11 additions and 9 deletions

View File

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

View File

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

View File

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