Example Program
Allocators
Examples for memory allocation.
1#include <seqan/basic.h>
2using namespace seqan;
3
4//An arbitrary class
5struct MyClass
6{
7};
8
9int main()
10{
The following code creates 100 instances of MyClass on the heap. The allocator object used is a temporary 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 must 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 allocator, but dedicated allocators offer more advanced functionality, e.g. clear.
16    Allocator<SimpleAlloc< > > alloc1;
17    allocate(alloc1, my_class_arr, 200);
18
19    char * char_array;
20    allocate(alloc1, char_array, 300);
21
22    clear(alloc1); //deallocated all storage at once.
23    
24    return 0;
25}
SeqAn - Sequence Analysis Library - www.seqan.de