MemoryPoolManager#
-
class numpy::MemoryPoolManager#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use MemoryPoolManager
MemoryPoolManager obj;
// ... operations ...
Indexing / Selection#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
MemoryPool<T>& |
NP_MEMORY_POOL.H:175 |
|
|
typename MemoryPool<T>::Statistics |
NP_MEMORY_POOL.H:202 |
Logical#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
T * |
NP_MEMORY_POOL.H:182 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
void |
NP_MEMORY_POOL.H:192 |
|
|
void |
NP_MEMORY_POOL.H:197 |
|
|
void |
NP_MEMORY_POOL.H:187 |
Code Examples#
The following examples are extracted from the test suite.
allocate (np_test_2_all.cpp:4418)
4408 using namespace numpy::memory;
4409
4410 namespace test_memory_pool {
4411
4412 void test_memory_pool_basic_allocate() {
4413 std::cout << "========= test_memory_pool_basic_allocate =======================";
4414
4415 MemoryPool<int> pool;
4416
4417 // Test basic allocation
4418 int* ptr1 = pool.allocate(100);
4419 if (!(ptr1 != nullptr)) {
4420 std::string description = std::string("test_memory_pool_basic_allocate():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ptr1 != nullptr)";
4421 std::cout << std::string("[FAIL] ") + description << std::endl;
4422 throw std::runtime_error(description);
4423 }
4424
4425 // Test writing to allocated memory
4426 for (int i = 0; i < 100; ++i) {
4427 ptr1[i] = i;
4428 }
deallocate (np_test_2_all.cpp:4439)
4429 // Verify data integrity
4430 for (int i = 0; i < 100; ++i) {
4431 if (!(ptr1[i] == i)) {
4432 std::string description = std::string("test_memory_pool_basic_allocate():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ptr1[i] == i)";
4433 std::cout << std::string("[FAIL] ") + description << std::endl;
4434 throw std::runtime_error(description);
4435 }
4436 }
4437
4438 pool.deallocate(ptr1);
4439
4440 // std::cout << "Basic memory pool allocation test passed" << std::endl;
4441
4442 std::cout << " -> tests passed" << std::endl;
4443 }
4444
4445 void test_memory_pool_deallocate() {
4446 std::cout << "========= test_memory_pool_deallocate =======================";
4447
4448 MemoryPool<double> pool;