Allocators

| Example Program Allocators Examples for memory allocation. File "allocator.cpp" A tutorial about the use of allocators.
1 | #include <seqan/basic.h>
2 | using namespace seqan;
3 |
We define an arbitrary class.
4 | struct MyClass
5 | {
6 | };
7 |
8 | int main()
9 | {
We create 100 instances of MyClass on the heap using a default temporary allocator object Default.
10 | MyClass* my_class_arr;
11 | allocate(Default(), my_class_arr, 100);
12 | arrayConstruct(my_class_arr, my_class_arr + 100);
Before the storage is deallocated, the MyClass objects have to be destroyed.
13 | arrayDestruct(my_class_arr, my_class_arr + 100);
14 | deallocate(Default(), my_class_arr, 100);
We can use any kind of object as an allocator. However, dedicated allocators offer more advanced functionality, e.g. clear.
15 | Allocator<SimpleAlloc< > > alloc1;
16 | char * char_array;
17 | allocate(alloc1, char_array, 300);
clear can be used to deallocate all storage at once.
18 | clear(alloc1);
19 | return 0;
20 | }
See arrayConstruct, clear, allocate, arrayDestruct, deallocate, Allocator See Also Single Pool Allocator, Multi Pool Allocator SeqAn - Sequence Analysis Library - www.seqan.de

Page built @2011/02/08 21:37:00