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