Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tpl_memArray.H File Reference

Simple, scalable, contiguous dynamic array. More...

#include <utility>
#include <cstdlib>
#include <cmath>
#include <stdexcept>
#include <ah-errors.H>
#include <ahUtils.H>
#include <ahDry.H>
#include <ahIterator.H>
#include <array_it.H>
#include <array_utils.H>
Include dependency graph for tpl_memArray.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Aleph::MemArray< T >
 Simple, scalable and fast dynamic array. More...
 
struct  Aleph::MemArray< T >::Iterator
 Simple iterator on elements of array. More...
 

Namespaces

namespace  Aleph
 Main namespace for Aleph-w library functions.
 

Detailed Description

Simple, scalable, contiguous dynamic array.

This file provides MemArray, a dynamic array that maintains all elements in a single contiguous memory block. Unlike DynArray (which uses a two-level directory), MemArray offers direct array-like access but requires reallocation when growing beyond capacity.

Key Features

  • Contiguous memory layout (cache-friendly)
  • Direct O(1) access like raw arrays
  • Automatic growth with configurable factor
  • Move semantics for efficient transfers
  • STL-compatible iteration

Complexity

Operation Time Notes
access [] O(1) Direct memory access
append O(1) amortized O(n) when reallocating
insert at i O(n-i) Shifts elements
remove at i O(n-i) Shifts elements
reserve O(n) May reallocate

Growth Strategy

When capacity is exceeded, the array grows by a configurable factor (default: 2x). This gives amortized O(1) appends.

Comparison with DynArray

Feature MemArray DynArray
Memory layout Contiguous Two-level directory
Reallocation Full copy Segment-based
Cache locality Excellent Good
Large arrays May fail to allocate Handles well

Usage Example

MemArray<int> arr(100); // Initial capacity 100
arr.append(42); // Add element
arr[0] = 17; // Direct access
for (auto& x : arr) // Range-based for
std::cout << x << " ";
STL namespace.
See also
tpl_dynArray.H For very large arrays or frequent resizing
tpl_arrayStack.H Stack built on MemArray
tpl_arrayQueue.H Queue built on MemArray
Author
Leandro Rabindranath León

Definition in file tpl_memArray.H.