### Boost Pool: 'pool' Interface Example (C++) Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/boost_pool/pool/interfaces Example usage of the Boost.Pool 'pool' interface. It demonstrates creating a pool for integers, allocating multiple integers within a loop, and relying on the pool's destructor to automatically free the allocated memory upon exiting the scope. ```cpp void func() { boost::pool<> p(sizeof(int)); for (int i = 0; i < 10000; ++i) { int * const t = p.malloc(); ... // Do something with t; don't take the time to free() it. } } // on function exit, p is destroyed, and all malloc()'ed ints are implicitly freed. ``` -------------------------------- ### Boost Pool Library Include Directive Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/boost_pool/pool/conventions This code snippet shows the necessary include directive to use all files from the Boost Pool library. It's a common starting point for projects utilizing Boost.Pool. ```cpp // Include all of Pool files #include ``` -------------------------------- ### simple_segregated_storage try_malloc_n Static Function Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1simple__segregated__storage Attempts to allocate `n` contiguous chunks of `partition_size` from the free list starting at `start`. Returns the last chunk if successful, otherwise 0. Updates `start` to the last considered chunk. ```cpp static void * try_malloc_n(void *& start, size_type n, size_type partition_size); ``` -------------------------------- ### simple_segregated_storage add_block Public Member Function Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1simple__segregated__storage Adds a memory block to the segregated storage. `block` is the start of the memory, `chunk_size` is the size of each chunk, and `chunks` is the total number of chunks. ```cpp void add_block(void *const block, const size_type chunk_size, const size_type chunks); ``` -------------------------------- ### simple_segregated_storage ordered_free_n Public Member Function Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1simple__segregated__storage Frees `n` contiguous memory chunks and attempts to maintain the order of the free list. `ptr` is the starting chunk, and `partition_size` is the size of each chunk. ```cpp void ordered_free_n(void *const ptr, const size_type n, const size_type partition_size); ``` -------------------------------- ### Pool Size Configuration Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1pool Functions to get and set the next allocation size and maximum allocation size for the pool. `get_next_size` retrieves the number of chunks to request for the next system allocation, and `set_next_size` configures this value. `get_max_size` retrieves the maximum number of chunks to allocate in a block, and `set_max_size` configures this. ```cpp size_type get_next_size() const; void set_next_size(const size_type nnext_size); size_type get_max_size() const; void set_max_size(const size_type nmax_size); ``` -------------------------------- ### simple_segregated_storage free_n Public Member Function Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1simple__segregated__storage Frees `n` contiguous memory chunks starting from `ptr`, each of size `partition_size`. Returns these chunks to the free list. ```cpp void free_n(void *const ptr, const size_type n, const size_type partition_size); ``` -------------------------------- ### C++ Singleton Pool for Memory Management Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/boost_pool/pool/interfaces The singleton_pool interface in C++ provides a singleton instance for memory management, similar to the general pool interface but with singleton semantics. It is designed for thread-safe access if used within specific concurrency constraints (before main() starts and after main() ends). Each set of template parameters defines a unique underlying pool. ```cpp template struct singleton_pool { public: typedef Tag tag; typedef UserAllocator user_allocator; typedef typename pool::size_type size_type; typedef typename pool::difference_type difference_type; static const unsigned requested_size = RequestedSize; private: static pool p; // exposition only! singleton_pool(); public: static bool is_from(void * ptr); static void * malloc(); static void * ordered_malloc(); static void * ordered_malloc(size_type n); static void free(void * ptr); static void ordered_free(void * ptr); static void free(void * ptr, std::size_t n); static void ordered_free(void * ptr, size_type n); static bool release_memory(); static bool purge_memory(); }; // Example Usage: struct MyPoolTag { }; typedef boost::singleton_pool my_pool; void func() { for (int i = 0; i < 10000; ++i) { int * const t = my_pool::malloc(); // ... Do something with t; don't take the time to free() it. } // Explicitly free all malloc()'ed ints. my_pool::purge_memory(); } ``` -------------------------------- ### Boost simple_segregated_storage Class Template Synopsis Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1simple__segregated__storage This snippet provides the complete synopsis for the `simple_segregated_storage` class template, outlining its template parameters, types, constructors, and member functions. It is defined in the `` header. ```cpp // In header: template class simple_segregated_storage { public: // types typedef SizeType size_type; // private member functions simple_segregated_storage(const simple_segregated_storage &); void operator=(const simple_segregated_storage &); // private static functions static void * try_malloc_n(void *&, size_type, size_type); // protected member functions void * find_prev(void *); // protected static functions static void *& nextof(void *const); // public member functions simple_segregated_storage(); void add_block(void *const, const size_type, const size_type); void add_ordered_block(void *const, const size_type, const size_type); bool empty() const; void * malloc(); void free(void *const); void ordered_free(void *const); void * malloc_n(size_type, size_type); void free_n(void *const, const size_type, const size_type); void ordered_free_n(void *const, const size_type, const size_type); // public static functions static void * segregate(void *, size_type, size_type, void * = 0); }; ``` -------------------------------- ### Get next allocation size from object_pool Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1object__pool Retrieves the number of chunks that will be allocated the next time the pool needs to replenish its memory supply. ```cpp size_type get_next_size() const; ``` -------------------------------- ### Boost pool_allocator Class Template Synopsis Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1pool__allocator The synopsis for the `boost::pool_allocator` class template, outlining its structure and available member and static functions. It requires the `` header. ```cpp // In header: template class pool_allocator { public: // public member functions pool_allocator(); template pool_allocator(const pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > &); bool operator==(const pool_allocator &) const; bool operator!=(const pool_allocator &) const; // public static functions static pointer address(reference); static const_pointer address(const_reference); static size_type max_size(); static void construct(const pointer, const value_type &); static void destroy(const pointer); static pointer allocate(const size_type); static pointer allocate(const size_type, const void * const); static void deallocate(const pointer, const size_type); }; ``` -------------------------------- ### Boost Pool: 'pool' Interface Synopsis (C++) Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/boost_pool/pool/interfaces Synopsis for the 'pool' template class in Boost.Pool. It outlines the class structure, constructors, destructors, and key methods for memory management (allocation, deallocation, memory release/purge) and querying pool properties. It supports custom user allocators. ```cpp template class pool { private: pool(const pool &); void operator=(const pool &); public: typedef UserAllocator user_allocator; typedef typename UserAllocator::size_type size_type; typedef typename UserAllocator::difference_type difference_type; explicit pool(size_type requested_size); ~pool(); bool release_memory(); bool purge_memory(); bool is_from(void * chunk) const; size_type get_requested_size() const; void * malloc(); void * ordered_malloc(); void * ordered_malloc(size_type n); void free(void * chunk); void ordered_free(void * chunk); void free(void * chunks, size_type n); void ordered_free(void * chunks, size_type n); }; ``` -------------------------------- ### Initialize simple_segregated_storage (C++) Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1simple__segregated__storage The constructor for `simple_segregated_storage` initializes an empty storage area. After construction, the storage is guaranteed to be empty, satisfying the `empty()` postcondition. ```C++ simple_segregated_storage(); ``` -------------------------------- ### simple_segregated_storage Default Constructor Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1simple__segregated__storage The default constructor for `simple_segregated_storage`, initializing an empty storage object. ```cpp simple_segregated_storage(); ``` -------------------------------- ### Get Next Pointer: nextof Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1pool The `nextof` function returns a dereferenced pointer to the next element. This function is primarily for code readability, providing a more intuitive way to access sequential elements within a memory structure managed by the pool. ```cpp static void *& nextof(void *const ptr); // Returns: Pointer dereferenced. ``` -------------------------------- ### Synopsis of Simple Segregated Storage Class (C++) Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/boost_pool/pool/pooling The 'simple_segregated_storage' class template controls access to a free list of memory chunks. It's designed for speed and minimal footprint, suitable for embedded systems. User must manage preconditions, especially alignment. Key methods include adding blocks, allocating and freeing chunks, and allocating/freeing multiple chunks. ```cpp template class simple_segregated_storage { private: simple_segregated_storage(const simple_segregated_storage &); void operator=(const simple_segregated_storage &); public: typedef SizeType size_type; simple_segregated_storage(); ~simple_segregated_storage(); static void * segregate(void * block, size_type nsz, size_type npartition_sz, void * end = 0); void add_block(void * block, size_type nsz, size_type npartition_sz); void add_ordered_block(void * block, size_type nsz, size_type npartition_sz); bool empty() const; void * malloc(); void free(void * chunk); void ordered_free(void * chunk); void * malloc_n(size_type n, size_type partition_sz); void free_n(void * chunks, size_type n, size_type partition_sz); void ordered_free_n(void * chunks, size_type n, size_type partition_sz); }; ``` -------------------------------- ### Get Pointer to Next Element in simple_segregated_storage (C++) Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1simple__segregated__storage The `nextof` function returns a pointer to the next element in a memory block, cast to the appropriate type. It requires that the input pointer is not null. This is a convenience function for simplifying pointer dereferencing and assignment operations within the storage management. ```C++ static void *& nextof(void *const ptr); ``` -------------------------------- ### fast_pool_allocator Constructor Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1fast__pool__allocator Constructors for the `fast_pool_allocator`. These ensure the underlying singleton_pool is constructed if an instance of the allocator is created during global initialization. This is important for managing the lifecycle of the pool instance, especially in scenarios involving global objects. ```cpp fast_pool_allocator(); ``` ```cpp template fast_pool_allocator(const fast_pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > &); ``` -------------------------------- ### simple_segregated_storage Public Member Functions Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1simple__segregated__storage Core functions for initializing, managing, allocating, and freeing memory blocks within the simple_segregated_storage. ```APIDOC ## simple_segregated_storage() ### Description Constructs an empty storage area. ### Method constructor ### Endpoint N/A ### Parameters None ### Request Example ```cpp simple_segregated_storage storage; ``` ### Response #### Success Response (200) Initializes an empty simple_segregated_storage object. #### Response Example ```json // No direct response, object is initialized. ``` ``` ```APIDOC ## void add_block(void *const block, const size_type nsz, const size_type npartition_sz) ### Description Adds a memory block to the storage. It segregates the block and merges its free list into the main free list. ### Method void ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **block** (void *const) - Pointer to the memory block to add. - **nsz** (size_type) - The total size of the block. - **npartition_sz** (size_type) - The size of each partition within the block. ### Request Example ```cpp void* my_block = malloc(1024); storage.add_block(my_block, 1024, 64); ``` ### Response #### Success Response (200) Adds the block to the storage. Postcondition: !empty(). #### Response Example ```json // No direct response, operation modifies internal state. ``` ``` ```APIDOC ## void add_ordered_block(void *const block, const size_type nsz, const size_type npartition_sz) ### Description Adds a memory block to the storage in an ordered fashion. This is a slower version of `add_block` that maintains the order of the free list. ### Method void ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **block** (void *const) - Pointer to the memory block to add. - **nsz** (size_type) - The total size of the block. - **npartition_sz** (size_type) - The size of each partition within the block. ### Request Example ```cpp void* my_block = malloc(1024); storage.add_ordered_block(my_block, 1024, 64); ``` ### Response #### Success Response (200) Adds the block in order to the storage. #### Response Example ```json // No direct response, operation modifies internal state. ``` ``` ```APIDOC ## bool empty() const ### Description Checks if the `simple_segregated_storage` is empty. ### Method bool ### Endpoint N/A ### Parameters None ### Request Example ```cpp if (storage.empty()) { // storage is empty } ``` ### Response #### Success Response (200) - **true only if simple_segregated_storage is empty.** (bool) - Returns true if the storage is empty, false otherwise. ``` ```APIDOC ## void * malloc() ### Description Allocates and returns a chunk of memory from the storage. Requires that the storage is not empty. ### Method void * ### Endpoint N/A ### Parameters None ### Request Example ```cpp void* chunk = storage.malloc(); ``` ### Response #### Success Response (200) - **Pointer to the allocated chunk** (void *) - Returns a pointer to the allocated memory chunk. Requires: !empty(). ``` ```APIDOC ## void free(void *const chunk) ### Description Frees a previously allocated chunk of memory, returning it to the storage. ### Method void ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **chunk** (void *const) - Pointer to the memory chunk to free. ### Request Example ```cpp void* my_chunk = storage.malloc(); // ... use my_chunk ... storage.free(my_chunk); ``` ### Response #### Success Response (200) Frees the specified chunk. Postconditions: !empty(). Requires: chunk was previously returned from a malloc() referring to the same free list. #### Response Example ```json // No direct response, operation modifies internal state. ``` ``` ```APIDOC ## void ordered_free(void *const chunk) ### Description Frees a previously allocated chunk of memory and inserts it back into the free list in its proper order. This is a slower version of `free`. ### Method void ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **chunk** (void *const) - Pointer to the memory chunk to free. ### Request Example ```cpp void* my_chunk = storage.malloc(); // ... use my_chunk ... storage.ordered_free(my_chunk); ``` ### Response #### Success Response (200) Frees the chunk and inserts it in order. Postconditions: !empty(). Requires: chunk was previously returned from a malloc() referring to the same free list. #### Response Example ```json // No direct response, operation modifies internal state. ``` ``` ```APIDOC ## void * malloc_n(size_type n, size_type partition_size) ### Description Attempts to find and allocate a contiguous sequence of `n` chunks, each of `partition_size`. If successful, it removes them from the free list and returns a pointer to the first chunk. Returns `0` if not found. Order-preserving. ### Method void * ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **n** (size_type) - The number of contiguous chunks to allocate. - **partition_size** (size_type) - The size of each partition. ### Request Example ```cpp void* contiguous_chunks = storage.malloc_n(5, 64); ``` ### Response #### Success Response (200) - **Pointer to the first chunk** (void *) - Returns a pointer to the first of the contiguous chunks if found, otherwise returns `0`. It is strongly recommended (but not required) that the free list be ordered. ``` ```APIDOC ## void free_n(void *const chunks, const size_type n, const size_type partition_size) ### Description Frees a contiguous sequence of `n` chunks, each of `partition_size`, previously allocated by `malloc_n`. ### Method void ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **chunks** (void *const) - Pointer to the first chunk in the contiguous sequence. - **n** (size_type) - The number of contiguous chunks to free. - **partition_size** (size_type) - The size of each partition. ### Request Example ```cpp void* my_chunks = storage.malloc_n(5, 64); // ... use my_chunks ... storage.free_n(my_chunks, 5, 64); ``` ### Response #### Success Response (200) Frees the specified contiguous chunks. Postconditions: !empty(). Requires: chunks was previously allocated from *this with the same values for n and partition_size. #### Response Example ```json // No direct response, operation modifies internal state. ``` ``` ```APIDOC ## void ordered_free_n(void *const chunks, const size_type n, const size_type partition_size) ### Description Frees a contiguous sequence of `n` chunks, each of `partition_size`, and inserts them back into the free list in their proper order. This is a slower version of `free_n`. ### Method void ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **chunks** (void *const) - Pointer to the first chunk in the contiguous sequence. - **n** (size_type) - The number of contiguous chunks to free. Should not be zero. - **partition_size** (size_type) - The size of each partition. ### Request Example ```cpp void* my_chunks = storage.malloc_n(5, 64); // ... use my_chunks ... storage.ordered_free_n(my_chunks, 5, 64); ``` ### Response #### Success Response (200) Frees the contiguous chunks and inserts them in order. Postconditions: !empty(). Requires: chunks was previously allocated from *this with the same values for n and partition_size. Requires: n should not be zero (n == 0 has no effect). #### Response Example ```json // No direct response, operation modifies internal state. ``` ``` -------------------------------- ### Boost singleton_pool Class Template Synopsis (C++) Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1singleton__pool The synopsis for the boost::singleton_pool class template, declared in . This template provides a single-instance memory pool with customizable user allocators and mutexes. It allows for efficient allocation and deallocation of memory chunks. ```cpp // In header: template class singleton_pool { public: // types typedef Tag tag; typedef Mutex mutex; typedef UserAllocator user_allocator; typedef pool< UserAllocator >::size_type size_type; typedef pool< UserAllocator >::difference_type difference_type; struct object_creator { object_creator(); void do_nothing() const; }; singleton_pool(); // public static functions static void * malloc(); static void * ordered_malloc(); static void * ordered_malloc(const size_type); static bool is_from(void *const); static void free(void *const); static void ordered_free(void *const); static void free(void *const, const size_type); static void ordered_free(void *const, const size_type); static bool release_memory(); static bool purge_memory(); private: static pool_type & get_pool(); public: static const unsigned requested_size; static const unsigned next_size; static pool< UserAllocator > p; }; ``` -------------------------------- ### Memory Allocation Functions Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1pool Functions for allocating memory chunks. `malloc` allocates a single chunk, searching for free chunks in existing blocks or allocating a new block if necessary. `ordered_malloc` is similar but merges free lists to preserve order. An overload of `ordered_malloc(size_type n)` gets the address of a specific chunk 'n', allocating memory if needed. ```cpp void * malloc(); void * ordered_malloc(); void * ordered_malloc(size_type n); ``` -------------------------------- ### Forward Declarations for Boost Pool Library Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/poolfwd_8hpp This snippet shows the forward declarations for key classes within the Boost Pool library. These are typically found in the `` header. They allow for incomplete type declarations, useful for reducing compile times and managing dependencies. ```cpp namespace boost { template class fast_pool_allocator; template class object_pool; template class pool; template class pool_allocator; } ``` -------------------------------- ### fast_pool_allocator Object Management Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1fast__pool__allocator Functions for managing objects within the `fast_pool_allocator`. `construct` is used to construct an object at a specified memory location, and `destroy` is used to call the destructor of an object at a specified memory location, ensuring proper resource cleanup. ```cpp void construct(const pointer ptr, const value_type & t); ``` ```cpp void destroy(const pointer ptr); ``` -------------------------------- ### Boost pool_allocator Copy Constructor Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1pool__allocator The copy constructor for `boost::pool_allocator`. It also ensures the underlying singleton_pool is constructed if an instance is created during global initialization, as per Boost ticket #2359. ```cpp template pool_allocator(const pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > &); ``` -------------------------------- ### Boost pool Class Template Synopsis Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1pool This is the synopsis for the Boost pool class template, outlining its protected and public member functions. It details memory allocation, deallocation, and pool management functionalities. ```cpp template class pool : protected boost::simple_segregated_storage< UserAllocator::size_type > { public: // private member functions void * malloc_need_resize(); void * ordered_malloc_need_resize(); // protected member functions simple_segregated_storage< size_type > & store(); const simple_segregated_storage< size_type > & store() const; details::PODptr< size_type > find_POD(void *const) const; size_type alloc_size() const; size_type max_chunks() const; // protected static functions static bool is_from(void *const, char *const, const size_type); static void *& nextof(void *const); // public member functions explicit pool(const size_type, const size_type = 32, const size_type = 0); ~pool(); bool release_memory(); bool purge_memory(); size_type get_next_size() const; void set_next_size(const size_type); size_type get_max_size() const; void set_max_size(const size_type); size_type get_requested_size() const; void * malloc(); void * ordered_malloc(); void * ordered_malloc(size_type); void free(void *const); void ordered_free(void *const); void free(void *const, const size_type); void ordered_free(void *const, const size_type); bool is_from(void *const) const; }; ``` -------------------------------- ### Boost pool_allocator Synopsis Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1pool__allocator_3_01void_00_01UserAllocator_00_01Mutex_00_01NextSize_00_01MaxSize_01_4 This C++ code snippet shows the synopsis for the `boost::pool_allocator` class template. It includes type definitions like `pointer`, `const_pointer`, and `value_type`, along with a nested `rebind` struct that allows for transforming the allocator for different types. ```cpp // In header: template class pool_allocator { public: // types typedef void * pointer; typedef const void * const_pointer; typedef void value_type; // member classes/structs/unions // Nested class rebind allows for transformation from pool_allocator to pool_allocator. template struct rebind { // types typedef pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > other; }; }; ``` -------------------------------- ### singleton_pool Class Declaration (C++) Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/singleton__pool_8hpp This C++ code snippet shows the template declaration for the `singleton_pool` class within the `boost` namespace. It defines the class and its various template parameters, including `Tag`, `RequestedSize`, `UserAllocator`, `Mutex`, `NextSize`, and `MaxSize`, which configure the behavior and characteristics of the singleton pool. ```cpp namespace boost { template class singleton_pool; } ``` -------------------------------- ### fast_pool_allocator Synopsis Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1fast__pool__allocator The synopsis for the `fast_pool_allocator` class template, which is a C++ Standard Library conforming allocator optimized for allocating single chunks of memory. It includes constructors, member functions for object construction/destruction, comparison operators, and static functions for memory allocation/deallocation and retrieving maximum size. ```cpp // In header: template class fast_pool_allocator { public: // public member functions fast_pool_allocator(); template fast_pool_allocator(const fast_pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > &); void construct(const pointer, const value_type &); void destroy(const pointer); bool operator==(const fast_pool_allocator &) const; bool operator!=(const fast_pool_allocator &) const; // public static functions static pointer address(reference); static const_pointer address(const_reference); static size_type max_size(); static pointer allocate(const size_type); static pointer allocate(const size_type, const void * const); static pointer allocate(); static void deallocate(const pointer, const size_type); static void deallocate(const pointer); }; ``` -------------------------------- ### Simple Segregated Storage Template Declaration Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/simple__segregated__storage_8hpp Declares the simple_segregated_storage template class with a configurable SizeType parameter. This class forms the foundation of the Boost Pool library and implements the simplest, fastest memory allocation/deallocation algorithm by partitioning memory blocks into fixed-size chunks. ```cpp namespace boost { template class simple_segregated_storage; } ``` -------------------------------- ### Boost pool_allocator Equality and Inequality Operators Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1pool__allocator The equality (`==`) and inequality (`!=`) operators for `boost::pool_allocator`. These allow comparison between two pool allocator instances. ```cpp bool operator==(const pool_allocator &) const; bool operator!=(const pool_allocator &) const; ``` -------------------------------- ### simple_segregated_storage find_prev Protected Member Function Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1simple__segregated__storage Traverses the free list and returns the iterator previous to where `ptr` would be inserted. Returns 0 if `ptr` would be at the beginning of the free list. ```cpp void * find_prev(void * ptr); ``` -------------------------------- ### Boost pool_allocator Static allocate Function Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1pool__allocator Static functions to allocate memory. One overload allocates a specified number of bytes, and another provides an additional hint pointer. ```cpp static pointer allocate(const size_type n); static pointer allocate(const size_type n, const void * const); ``` -------------------------------- ### simple_segregated_storage Public Static Functions Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1simple__segregated__storage Static utility function for segregating a memory block into manageable chunks. ```APIDOC ## void * segregate(void * block, size_type nsz, size_type npartition_sz, void * end = 0) ### Description Segregates a memory block into smaller chunks of a specified partition size. It returns a pointer to the first chunk. ### Method static void * ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **block** (void *) - Pointer to the memory block to segregate. - **nsz** (size_type) - The total size of the block. - **npartition_sz** (size_type) - The size of each partition within the block. - **end** (void *, optional) - Pointer to the end of the block. Defaults to 0. ### Request Example ```cpp void* memory_pool = malloc(4096); void* first_chunk = simple_segregated_storage::segregate(memory_pool, 4096, 64); ``` ### Response #### Success Response (200) - **Pointer to the first chunk** (void *) - Returns a pointer to the first segregated chunk. Requires: npartition_sz >= sizeof(void *) Requires: npartition_sz = sizeof(void *) * i, for some integer i Requires: nsz >= npartition_sz Requires: Block is properly aligned for an array of object of size npartition_sz and array of void *. ``` -------------------------------- ### Boost pool_allocator Static construct and destroy Functions Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1pool__allocator Static functions for constructing and destroying objects in allocated memory. `construct` places an object in memory, and `destroy` destructs it. ```cpp static void construct(const pointer ptr, const value_type & t); static void destroy(const pointer ptr); ``` -------------------------------- ### Construct an object_pool Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1object__pool Constructs a new, optionally pre-sized, object pool. The `next_size` parameter determines the number of chunks allocated when the pool runs out of memory, and `max_size` sets an upper limit on the pool's capacity. Requires `next_size` to be non-zero. ```cpp explicit object_pool(const size_type arg_next_size = 32, const size_type arg_max_size = 0); ``` -------------------------------- ### fast_pool_allocator Comparison Operators Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1fast__pool__allocator Comparison operators for the `fast_pool_allocator`. These operators (`==` and `!=`) allow for the comparison of two allocator instances, typically used to determine if they refer to the same underlying memory pool or have compatible configurations. ```cpp bool operator==(const fast_pool_allocator &) const; ``` ```cpp bool operator!=(const fast_pool_allocator &) const; ``` -------------------------------- ### Define fast_pool_allocator_tag Struct (C++) Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/structboost_1_1fast__pool__allocator__tag Defines the `fast_pool_allocator_tag` struct, a simple tag type used by `fast_pool_allocator`. This struct is found in the `` header. ```cpp #include struct fast_pool_allocator_tag { }; ``` -------------------------------- ### Define object_creator struct in Boost singleton_pool C++ Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/structboost_1_1singleton__pool_1_1object__creator The object_creator struct is defined in the boost::singleton_pool namespace within the pool library header. It contains a public constructor and a do_nothing const member function used for object creation management in singleton pool implementations. ```cpp struct object_creator { // public member functions object_creator(); void do_nothing() const; }; ``` -------------------------------- ### fast_pool_allocator Interface Definition (C++) Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/boost_pool/pool/interfaces Defines the `fast_pool_allocator` class template, offering a specialized, high-performance memory allocation strategy. It also adheres to Standard Allocator requirements and supports user-defined allocators. Includes methods for allocation, deallocation, and object management, with additional overloads for single object operations. ```C++ struct fast_pool_allocator_tag { }; template class fast_pool_allocator { public: typedef UserAllocator user_allocator; typedef T value_type; typedef value_type * pointer; typedef const value_type * const_pointer; typedef value_type & reference; typedef const value_type & const_reference; typedef typename pool::size_type size_type; typedef typename pool::difference_type difference_type; template struct rebind { typedef fast_pool_allocator other; }; public: fast_pool_allocator(); fast_pool_allocator(const fast_pool_allocator &); // The following is not explicit, mimicking std::allocator [20.4.1] template fast_pool_allocator(const fast_pool_allocator &); fast_pool_allocator & operator=(const fast_pool_allocator &); ~fast_pool_allocator(); static pointer address(reference r); static const_pointer address(const_reference s); static size_type max_size(); static void construct(pointer ptr, const value_type & t); static void destroy(pointer ptr); bool operator==(const fast_pool_allocator &) const; bool operator!=(const fast_pool_allocator &) const; static pointer allocate(size_type n); static pointer allocate(size_type n, pointer); static void deallocate(pointer ptr, size_type n); static pointer allocate(); static void deallocate(pointer ptr); }; ``` -------------------------------- ### simple_segregated_storage malloc_n Public Member Function Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1simple__segregated__storage Allocates `n` contiguous memory chunks of size `partition_size`. Returns a pointer to the first chunk if successful, otherwise null. ```cpp void * malloc_n(size_type n, size_type partition_size); ``` -------------------------------- ### Boost Pool Allocator: default_user_allocator_malloc_free Synopsis (C++) Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/structboost_1_1default__user__allocator__malloc__free This code snippet shows the synopsis for the `default_user_allocator_malloc_free` struct in C++. It defines types like `size_type` and `difference_type`, and declares static `malloc` and `free` functions for memory allocation and deallocation, intended for use with Boost.Pool. ```cpp // In header: struct default_user_allocator_malloc_free { // types typedef std::size_t size_type; // An unsigned integral type that can represent the size of the largest object to be allocated. typedef std::ptrdiff_t difference_type; // A signed integral type that can represent the difference of any two pointers. // public static functions static char * malloc(const size_type); static void free(char *const); }; ``` -------------------------------- ### Pool Constructor and Destructor Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1pool Constructs a new empty Pool with specified chunk size, next allocation size, and maximum allocation size. The destructor frees the Pool's memory blocks. ```cpp explicit pool(const size_type nrequested_size, const size_type nnext_size = 32, const size_type nmax_size = 0); ~pool(); ``` -------------------------------- ### singleton_pool Constructor and Type Definitions Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1singleton__pool Declares the private constructor of singleton_pool and the public Tag typedef. The Tag template parameter uniquely identifies each pool instance and prevents different singleton pool types from sharing the same underlying pool. The constructor is private to prevent instantiation. ```cpp singleton_pool(); typedef Tag tag; ``` -------------------------------- ### Boost Pool Allocator Namespace Declarations (C++) Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/pool_8hpp This snippet declares the default user allocator types within the 'boost' namespace for the Boost Pool library. These allocators are intended for use with the 'pool' class, which provides a fast memory allocator. No external dependencies are required to understand these declarations. ```cpp namespace boost { struct default_user_allocator_malloc_free; struct default_user_allocator_new_delete; } ``` -------------------------------- ### Construct an object with arguments in object_pool Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1object__pool Allocates memory from the pool and constructs an object of `ElementType` using the provided arguments. This function uses a preprocessor-generated system (via m4) to handle an arbitrary number of arguments and their permutations of cv-qualifiers, which can lead to exponential code growth. The returned object can be freed with `destroy` or will be automatically destroyed when the pool is destroyed. ```cpp template element_type * construct(Arg1 &, ... ArgN &); ``` -------------------------------- ### fast_pool_allocator Static Allocation Functions Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1fast__pool__allocator Static functions for memory allocation. `allocate` is provided in multiple overloads to request memory blocks of a specified size, potentially with additional context, or a default size. This is the core function for obtaining memory from the pool. ```cpp static pointer allocate(const size_type n); ``` ```cpp static pointer allocate(const size_type n, const void * const); ``` ```cpp static pointer allocate(); ``` -------------------------------- ### Synopsis of Boost object_pool Class Template (C++) Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1object__pool This C++ code snippet shows the synopsis of the 'boost::object_pool' class template. It outlines the template parameters, protected and public member functions, and static functions available for memory management. This class is designed for fast and efficient memory allocation of objects and automatic destruction of non-deallocated objects. ```cpp // In header: template class object_pool : protected boost::pool< UserAllocator > { public: // protected member functions pool< UserAllocator > & store(); const pool< UserAllocator > & store() const; // protected static functions static void *& nextof(void *const); // public member functions explicit object_pool(const size_type = 32, const size_type = 0); ~object_pool(); element_type * malloc(); void free(element_type *const); bool is_from(element_type *const) const; element_type * construct(); template element_type * construct(Arg1 &, ... ArgN &); void destroy(element_type *const); size_type get_next_size() const; void set_next_size(const size_type); }; ``` -------------------------------- ### Boost Pool: Default User Allocators (C++) Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/boost_pool/pool/interfaces Defines two default user allocator classes for the Boost pool interface: 'default_user_allocator_new_delete' which uses 'new' and 'delete[]', and 'default_user_allocator_malloc_free' which uses 'malloc' and 'free'. These allocators handle memory allocation and deallocation for pool objects. ```cpp struct default_user_allocator_new_delete { typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; static char * malloc(const size_type bytes) { return new (std::nothrow) char[bytes]; } static void free(char * const block) { delete [] block; } }; struct default_user_allocator_malloc_free { typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; static char * malloc(const size_type bytes) { return reinterpret_cast(std::malloc(bytes)); } static void free(char * const block) { std::free(block); } }; ``` -------------------------------- ### Free Chunk to simple_segregated_storage (C++) Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1simple__segregated__storage The `free` function returns a previously allocated chunk of memory back to the `simple_segregated_storage`. It requires that the chunk was obtained from the same free list and ensures that the storage is not empty after the operation. ```C++ void free(void *const chunk); ``` -------------------------------- ### simple_segregated_storage segregate Public Static Function Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1simple__segregated__storage A static utility function to segregate a memory block into fixed-size chunks. It takes the memory block, chunk size, and number of chunks as input. ```cpp static void * segregate(void * block, size_type chunk_size, size_type chunks, void * first_chunk = 0); ``` -------------------------------- ### Boost Pool: default_user_allocator_new_delete Struct Definition (C++) Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/structboost_1_1default__user__allocator__new__delete Defines the default_user_allocator_new_delete struct, which is used as a default template parameter for UserAllocator in Boost Pool. It leverages standard 'new' and 'delete' for memory operations and includes type definitions for size and difference. ```cpp #include struct default_user_allocator_new_delete { // types typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; // public static functions static char * malloc(const size_type); static void free(char *const); }; ``` -------------------------------- ### simple_segregated_storage Protected Functions Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1simple__segregated__storage Provides access to internal pointers for memory management within simple_segregated_storage. ```APIDOC ## void *& nextof(void *const ptr) ### Description Returns a reference to the next pointer in the free list, cast to a void pointer. This is a convenience function for easier manipulation of the free list pointers. ### Method static void *& ### Endpoint N/A (Internal function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp void* block = ...; void** next_ptr = static_cast(block); *next_ptr = 0; // Using explicit cast // Equivalent using nextof: nextof(block) = 0; // Using convenience function ``` ### Response #### Success Response (200) - **dereferenced pointer** (void *&) - A reference to the next pointer in the free list. ``` -------------------------------- ### singleton_pool Memory Management and Cleanup Functions Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1singleton__pool Static member functions for releasing and purging memory from the singleton pool. The release_memory() function frees unused memory blocks, while purge_memory() performs a complete purge operation. Both operations are synchronized and delegate to the underlying pool. ```cpp static bool release_memory(); static bool purge_memory(); ``` -------------------------------- ### Set next allocation size for object_pool Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1object__pool Sets the number of chunks to be allocated the next time the pool runs out of memory. The parameter `x` specifies the desired `next_size` and must not be zero. ```cpp void set_next_size(const size_type x); ``` -------------------------------- ### pool_allocator Interface Definition (C++) Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/boost_pool/pool/interfaces Defines the `pool_allocator` class template, which adheres to Standard Allocator requirements and is suitable for use in C++ containers. It utilizes a user-defined allocator for underlying memory management. Key methods include allocation, deallocation, construction, and destruction of objects. ```C++ struct pool_allocator_tag { }; template class pool_allocator { public: typedef UserAllocator user_allocator; typedef T value_type; typedef value_type * pointer; typedef const value_type * const_pointer; typedef value_type & reference; typedef const value_type & const_reference; typedef typename pool::size_type size_type; typedef typename pool::difference_type difference_type; template struct rebind { typedef pool_allocator other; }; public: pool_allocator(); pool_allocator(const pool_allocator &); // The following is not explicit, mimicking std::allocator [20.4.1] template pool_allocator(const pool_allocator &); pool_allocator & operator=(const pool_allocator &); ~pool_allocator(); static pointer address(reference r); static const_pointer address(const_reference s); static size_type max_size(); static void construct(pointer ptr, const value_type & t); static void destroy(pointer ptr); bool operator==(const pool_allocator &) const; bool operator!=(const pool_allocator &) const; static pointer allocate(size_type n); static pointer allocate(size_type n, pointer); static void deallocate(pointer ptr, size_type n); }; ``` -------------------------------- ### Fast Pool Allocator Specialization for void (C++) Source: https://www.boost.org/doc/libs/latest/libs/pool/doc/html/doxygen/boost_pool_c___reference/classboost_1_1fast__pool__allocator_3_01void_00_01UserAllocator_00_01Mutex_00_01NextSize_00_01MaxSize_01_4 This C++ code defines the specialization of the fast_pool_allocator class template for void. It ensures standard compliance for the allocator within the Boost pool library. It includes type definitions and a nested 'rebind' struct for transforming the allocator type. ```cpp // In header: template class fast_pool_allocator { public: // types typedef void * pointer; typedef const void * const_pointer; typedef void value_type; // member classes/structs/unions // Nested class rebind allows for transformation from fast_pool_allocator to fast_pool_allocator. template struct rebind { // types typedef fast_pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > other; }; }; ```