176using namespace Aleph;
177namespace fs = std::filesystem;
186 cout <<
"+" << string(70,
'-') <<
"+" <<
endl;
188 cout <<
"+" << string(70,
'-') <<
"+" <<
endl;
199 cout <<
" " << label <<
":" <<
endl;
200 cout <<
" Size (committed): " << arena.
size() <<
" bytes" <<
endl;
203 cout <<
" Is empty: " << (arena.
empty() ?
"yes" :
"no") <<
endl;
214 const string arena_file =
"/tmp/aleph_arena_basic.dat";
227 const char*
message =
"Hola desde Colombia!";
238 const char*
cities[] = {
"Bogota",
"Medellin",
"Cali",
"Barranquilla"};
261 cout <<
"\n Data synced to disk" <<
endl;
282 const string arena_file =
"/tmp/aleph_arena_struct.dat";
291 {
"Bogota", 8281, 1775.98, 2640},
292 {
"Medellin", 2569, 380.64, 1495},
293 {
"Cali", 2228, 564.33, 1018},
294 {
"Barranquilla", 1274, 154.00, 18},
295 {
"Cartagena", 1047, 609.10, 2}
301 char* ptr = arena.
reserve(
sizeof(
size_t));
303 arena.
commit(
sizeof(
size_t));
323 cout <<
" " << string(60,
'-') <<
endl;
324 cout <<
" " << left <<
setw(15) <<
"City"
325 << right <<
setw(10) <<
"Pop (k)"
326 <<
setw(12) <<
"Area (km2)"
328 cout <<
" " << string(60,
'-') <<
endl;
336 << right <<
setw(10) <<
rec.population
350 print_header(
"Example 3: Arena Growth (Automatic Remapping)");
352 const string arena_file =
"/tmp/aleph_arena_growth.dat";
367 const size_t chunk_size = 1000;
369 for (
int i = 0; i < 20; ++i) {
370 char* ptr = arena.
reserve(chunk_size);
373 memset(ptr,
'A' + (i % 26), chunk_size);
380 <<
" bytes (after " << arena.
size() <<
" allocated)" <<
endl;
390 cout <<
"\n Verifying data integrity..." <<
endl;
391 char* ptr = arena.
begin();
393 for (
int i = 0; i < 20 && valid; ++i) {
395 for (
size_t j = 0; j < chunk_size && valid; ++j) {
398 cout <<
" ERROR: Data corruption at chunk " << i <<
endl;
404 cout <<
" All data verified successfully!" <<
endl;
417 const string arena_file =
"/tmp/aleph_arena_log.dat";
426 "[2024-01-15 08:00:00] Sistema iniciado en Bogota",
427 "[2024-01-15 08:00:01] Conexion con servidor Medellin",
428 "[2024-01-15 08:00:02] Usuario: Juan Perez",
429 "[2024-01-15 08:00:05] Transaccion #1001: $150,000 COP",
430 "[2024-01-15 08:00:07] Sincronizacion con Cali",
431 "[2024-01-15 08:00:10] Backup iniciado",
432 "[2024-01-15 08:00:15] Backup completado",
433 "[2024-01-15 08:00:20] Alerta: Memoria al 75%"
439 size_t len =
strlen(entry) + 1;
440 char* ptr = arena.
reserve(len);
453 cout <<
" " << string(55,
'-') <<
endl;
455 char* ptr = arena.
begin();
457 while (ptr < arena.
end()) {
463 cout <<
" " << string(55,
'-') <<
endl;
477 const string arena_file =
"/tmp/aleph_arena_move.dat";
484 const char* data =
"Datos importantes de Colombia";
490 cout <<
" arena1 is_initialized: " <<
arena1.is_initialized() <<
endl;
496 cout <<
" After move construction:" <<
endl;
497 cout <<
" arena1 is_initialized: " <<
arena1.is_initialized() <<
endl;
498 cout <<
" arena2 is_initialized: " <<
arena2.is_initialized() <<
endl;
505 cout <<
" arena3 (before): is_initialized = " <<
arena3.is_initialized() <<
endl;
509 cout <<
" After move assignment:" <<
endl;
510 cout <<
" arena2 is_initialized: " <<
arena2.is_initialized() <<
endl;
511 cout <<
" arena3 is_initialized: " <<
arena3.is_initialized() <<
endl;
523 print_header(
"Example 6: Memory Statistics and Efficiency");
525 const string arena_file =
"/tmp/aleph_arena_stats.dat";
533 int allocations[] = {10, 50, 100, 500, 1000, 2000};
535 cout <<
"\n Allocation pattern analysis:" <<
endl;
536 cout <<
" " << string(50,
'-') <<
endl;
537 cout <<
" " <<
setw(10) <<
"Alloc Size"
538 <<
setw(12) <<
"Committed"
539 <<
setw(12) <<
"Capacity"
540 <<
setw(15) <<
"Utilization" <<
endl;
541 cout <<
" " << string(50,
'-') <<
endl;
549 double utilization = 100.0 * arena.
size() / arena.
capacity();
571 cout <<
"========================================================================" <<
endl;
572 cout <<
" ALEPH-W MAP ARENA EXAMPLE" <<
endl;
573 cout <<
" Memory-Mapped File Arena Allocator" <<
endl;
574 cout <<
"========================================================================" <<
endl;
584 cout <<
"========================================================================" <<
endl;
585 cout <<
" Example completed successfully!" <<
endl;
586 cout <<
"========================================================================" <<
endl;
Memory-mapped file arena allocator.
size_t size() const noexcept
Count the number of elements of the list.
Memory-mapped file arena allocator.
size_type size() const noexcept
Get the total committed (allocated) size.
size_type capacity() const noexcept
Get the current capacity (mapped region size).
void commit(const size_type sz) noexcept
Commit a previous reservation.
char * reserve(const size_type sz)
Reserve memory for allocation.
bool empty() const noexcept
Check if the arena is empty.
iterator end() noexcept
Get iterator past the last allocated byte.
static constexpr size_t initial_rgn_size
Initial region size in bytes (4 KB).
size_type avail() const noexcept
Get the available memory in the current mapping.
iterator begin() noexcept
Get iterator to the beginning of allocated memory.
void sync() noexcept
Ensure data is persisted to disk.
size_t length() const noexcept
Count the number of elements of a container.
iterator begin() noexcept
Return an STL-compatible iterator to the first element.
void print_arena_status(const MapArena &arena, const string &label)
void demo_basic_operations()
void demo_structured_data()
void print_subheader(const string &subtitle)
void demo_move_semantics()
Main namespace for Aleph-w library functions.
void message(const char *file, int line, const char *format,...)
Print an informational message with file and line info.
size_t size(Node *root) noexcept
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.