TPIE

11a2c2d
Memory manager

TPIE provides various external memory algorithms and data structures, most prominently an external memory priority queue (tpie::ami::priority_queue) and external memory sorting (tpie::sort). Although these algorithms work correctly with as little as a few megabytes of internal memory available, they will generally perform better the more internal memory they are assigned.

To use the external memory algorithms, you must initialize the memory subsystem using tpie::tpie_init. In order to specify the amount of internal memory to use, set the memory manager's limit as follows:

tpie::get_memory_manager().set_limit(megabytes*1024*1024);

See also tpie::memory_manager.

When you use TPIE to implement your own external memory algorithms, you should use tpie::tpie_new, tpie::tpie_new_array, tpie::tpie_delete and tpie::tpie_delete_array instead of new and delete whenever you allocate and deallocate large amounts of memory. This way, you can design your algorithms to work with the memory manager in TPIE, and built-in TPIE algorithms will respect the amount of memory your implementation has already allocated.

TPIE provides an implementation of the auto pointer paradigm. See tpie::unique_ptr.

int* my_ints = tpie::tpie_new_array<int>(1024);
std::fill(my_ints+0, my_ints+1024, 0);
tpie::tpie_delete_array(my_ints, 1024);
mystack->push(42);
// when mystack goes out of scope, the stack object is deleted with tpie_delete.

You can use the memory_manager methods tpie::memory_manager::used(), tpie::memory_manager::available() and tpie::memory_manager::limit() to inspect the internal memory environment.

tpie::resource_manager::set_limit
void set_limit(size_t new_limit)
Update the resource limit.
tpie::get_memory_manager
TPIE_EXPORT memory_manager & get_memory_manager()
Return a reference to the memory manager.
tpie::unique_ptr
std::unique_ptr< T, tpie_deleter > unique_ptr
like std::unique_ptr, but delete the object with tpie_delete.
Definition: memory.h:306
tpie::stack
An implementation of an external-memory stack.
Definition: stack.h:40
tpie::tpie_new
T * tpie_new(Args &&... args)
Allocate an element of the type given as template parameter, and register its memory usage with TPIE.
Definition: memory.h:260
tpie::tpie_delete_array
void tpie_delete_array(T *a, size_t size)
Delete an array allocated with tpie_new_array.
Definition: memory.h:288