1/*
2Open Asset Import Library (assimp)
3----------------------------------------------------------------------
4
5Copyright (c) 2006-2025, assimp team
6
7All rights reserved.
8
9Redistribution and use of this software in source and binary forms,
10with or without modification, are permitted provided that the
11following conditions are met:
12
13* Redistributions of source code must retain the above
14 copyright notice, this list of conditions and the
15 following disclaimer.
16
17* Redistributions in binary form must reproduce the above
18 copyright notice, this list of conditions and the
19 following disclaimer in the documentation and/or other
20 materials provided with the distribution.
21
22* Neither the name of the assimp team, nor the names of its
23 contributors may be used to endorse or promote products
24 derived from this software without specific prior
25 written permission of the assimp team.
26
27THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38----------------------------------------------------------------------
39*/
40
41/** @file StackAllocator.h
42 * @brief A very bare-bone allocator class that is suitable when
43 * allocating many small objects, e.g. during parsing.
44 * Individual objects are not freed, instead only the whole memory
45 * can be deallocated.
46 */
47#ifndef AI_STACK_ALLOCATOR_H_INC
48#define AI_STACK_ALLOCATOR_H_INC
49
50#include <vector>
51#include <stdint.h>
52#include <stddef.h>
53
54namespace Assimp {
55
56/** @brief A very bare-bone allocator class that is suitable when
57 * allocating many small objects, e.g. during parsing.
58 * Individual objects are not freed, instead only the whole memory
59 * can be deallocated.
60*/
61class StackAllocator {
62public:
63 /// @brief Constructs the allocator
64 StackAllocator();
65
66 /// @brief Destructs the allocator and frees all memory
67 ~StackAllocator();
68
69 // non copyable
70 StackAllocator(const StackAllocator &) = delete;
71 StackAllocator &operator=(const StackAllocator &) = delete;
72
73 /// @brief Returns a pointer to byteSize bytes of heap memory that persists
74 /// for the lifetime of the allocator (or until FreeAll is called).
75 inline void *Allocate(size_t byteSize);
76
77 /// @brief Releases all the memory owned by this allocator.
78 // Memory provided through function Allocate is not valid anymore after this function has been called.
79 inline void FreeAll();
80
81private:
82 constexpr const static size_t g_maxBytesPerBlock = 64 * 1024 * 1024; // The maximum size (in bytes) of a block
83 constexpr const static size_t g_startBytesPerBlock = 16 * 1024; // Size of the first block. Next blocks will double in size until maximum size of g_maxBytesPerBlock
84 size_t m_blockAllocationSize = g_startBytesPerBlock; // Block size of the current block
85 size_t m_subIndex = g_maxBytesPerBlock; // The current byte offset in the current block
86 std::vector<uint8_t *> m_storageBlocks; // A list of blocks
87};
88
89} // namespace Assimp
90
91/// @brief Fixes an undefined reference error when linking in certain build environments.
92// May throw warnings about needing stdc++17, but should compile without issues on modern compilers.
93inline const size_t Assimp::StackAllocator::g_maxBytesPerBlock;
94inline const size_t Assimp::StackAllocator::g_startBytesPerBlock;
95
96#include "StackAllocator.inl"
97
98#endif // include guard
99

source code of qtquick3d/src/3rdparty/assimp/src/code/Common/StackAllocator.h