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/SkeletonMeshBuilder.cpp
Common/StackAllocator.h
Common/StackAllocator.cpp
Common/StackAllocator.inl
Common/StandardShapes.cpp
Common/TargetAnimation.cpp
Common/TargetAnimation.h

View File

@ -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

View File

@ -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];
}