|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Example demonstrating MapArena memory-mapped file allocator. More...
#include <iostream>#include <iomanip>#include <string>#include <cstring>#include <filesystem>#include <ah-map-arena.H>Go to the source code of this file.
Classes | |
| struct | CityRecord |
Functions | |
| void | print_header (const string &title) |
| void | print_subheader (const string &subtitle) |
| void | print_arena_status (const MapArena &arena, const string &label) |
| void | demo_basic_operations () |
| void | demo_structured_data () |
| void | demo_arena_growth () |
| void | demo_log_buffer () |
| void | demo_move_semantics () |
| void | demo_memory_stats () |
| int | main () |
Example demonstrating MapArena memory-mapped file allocator.
This example demonstrates MapArena, a specialized memory allocator that uses memory-mapped files (mmap) as its backing store. This provides efficient memory management for large datasets and enables interesting persistence and sharing capabilities.
An arena allocator (also called a region allocator or bump allocator) is a memory management strategy where:
Advantages:
Disadvantages:
mmap() for backing storage| Operation | Complexity | Notes |
|---|---|---|
| Allocation | O(1) | Just pointer increment |
| Deallocation | O(1) | Free entire arena |
| Growth | O(n) | Remap operation |
| Iteration | O(n) | Linear scan |
Memory overhead: Minimal (just pointer tracking)
end_) not persisted to disk✅ Good for:
❌ Not good for:
Definition in file map_arena_example.C.
| void demo_arena_growth | ( | ) |
Definition at line 348 of file map_arena_example.C.
References Aleph::MapArena::begin(), Aleph::MapArena::capacity(), Aleph::MapArena::commit(), Aleph::MapArena::initial_rgn_size, Aleph::maps(), print_arena_status(), print_header(), print_subheader(), Aleph::MapArena::reserve(), and Aleph::MapArena::size().
Referenced by main().
| void demo_basic_operations | ( | ) |
Definition at line 210 of file map_arena_example.C.
References Aleph::MapArena::begin(), Aleph::MapArena::commit(), Aleph::MapArena::end(), Aleph::maps(), Aleph::message(), print_arena_status(), print_header(), print_subheader(), Aleph::MapArena::reserve(), and Aleph::MapArena::sync().
Referenced by main().
| void demo_log_buffer | ( | ) |
Definition at line 413 of file map_arena_example.C.
References Aleph::MapArena::begin(), Aleph::MapArena::commit(), Aleph::count(), Aleph::MapArena::end(), Aleph::maps(), print_arena_status(), print_header(), print_subheader(), and Aleph::MapArena::reserve().
Referenced by main().
| void demo_memory_stats | ( | ) |
Definition at line 521 of file map_arena_example.C.
References Aleph::MapArena::capacity(), Aleph::MapArena::commit(), Aleph::maps(), print_header(), print_subheader(), Aleph::MapArena::reserve(), Aleph::MapArena::size(), and Aleph::size().
Referenced by main().
| void demo_move_semantics | ( | ) |
Definition at line 473 of file map_arena_example.C.
References StlAlephIterator< SetName >::begin(), Aleph::maps(), print_header(), print_subheader(), and Aleph::HTList::size().
Referenced by main().
| void demo_structured_data | ( | ) |
Definition at line 278 of file map_arena_example.C.
References Aleph::MapArena::begin(), Aleph::MapArena::commit(), Aleph::count(), Aleph::maps(), print_arena_status(), print_header(), print_subheader(), and Aleph::MapArena::reserve().
Referenced by main().
| int main | ( | ) |
Definition at line 568 of file map_arena_example.C.
References demo_arena_growth(), demo_basic_operations(), demo_log_buffer(), demo_memory_stats(), demo_move_semantics(), demo_structured_data(), and Aleph::maps().
| void print_arena_status | ( | const MapArena & | arena, |
| const string & | label | ||
| ) |
Definition at line 197 of file map_arena_example.C.
References Aleph::MapArena::avail(), Aleph::MapArena::capacity(), Aleph::MapArena::empty(), Aleph::maps(), and Aleph::MapArena::size().
Referenced by demo_arena_growth(), demo_basic_operations(), demo_log_buffer(), and demo_structured_data().
| void print_header | ( | const string & | title | ) |
Definition at line 183 of file map_arena_example.C.
References Aleph::maps().
| void print_subheader | ( | const string & | subtitle | ) |
Definition at line 191 of file map_arena_example.C.
References FunctionalMethods< Container, T >::length(), and Aleph::maps().
Referenced by demo_arena_growth(), demo_basic_operations(), demo_log_buffer(), demo_memory_stats(), demo_move_semantics(), and demo_structured_data().