MemoryPoolManager ================= .. cpp:class:: numpy::MemoryPoolManager numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use MemoryPoolManager MemoryPoolManager obj; // ... operations ... Indexing / Selection -------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``MemoryPool& get_pool()`` - MemoryPool& - NP_MEMORY_POOL.H:175 - * - ``typename MemoryPool::Statistics get_pool_statistics()`` - typename MemoryPool::Statistics - NP_MEMORY_POOL.H:202 - Logical ------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``T \* allocate(size_tcount)`` - T \* - NP_MEMORY_POOL.H:182 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``void clear_pool()`` - void - NP_MEMORY_POOL.H:192 - * - ``void compact_pool()`` - void - NP_MEMORY_POOL.H:197 - * - ``void deallocate(T \*ptr)`` - void - NP_MEMORY_POOL.H:187 - :ref:`View ` Code Examples ------------- The following examples are extracted from the test suite. .. _example-memorypoolmanager-allocate-0: .. dropdown:: allocate (np_test_2_all.cpp:4418) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4408 :emphasize-lines: 11 using namespace numpy::memory; namespace test_memory_pool { void test_memory_pool_basic_allocate() { std::cout << "========= test_memory_pool_basic_allocate ======================="; MemoryPool pool; // Test basic allocation int* ptr1 = pool.allocate(100); if (!(ptr1 != nullptr)) { std::string description = std::string("test_memory_pool_basic_allocate():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ptr1 != nullptr)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test writing to allocated memory for (int i = 0; i < 100; ++i) { ptr1[i] = i; } .. _example-memorypoolmanager-deallocate-1: .. dropdown:: deallocate (np_test_2_all.cpp:4439) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4429 :emphasize-lines: 11 // Verify data integrity for (int i = 0; i < 100; ++i) { if (!(ptr1[i] == i)) { std::string description = std::string("test_memory_pool_basic_allocate():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ptr1[i] == i)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } pool.deallocate(ptr1); // std::cout << "Basic memory pool allocation test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_memory_pool_deallocate() { std::cout << "========= test_memory_pool_deallocate ======================="; MemoryPool pool;