58namespace fs = std::filesystem;
163 <<
"cannot truncate the file to " <<
new_size <<
" error = " <<
errno;
165 rgn_ptr =
static_cast<char*
>(ptr);
201 const auto status = ::read(
fd, &
end_,
sizeof(
end_));
217 <<
"cannot truncate the file to " <<
rgn_size <<
" error = " <<
errno;
223 <<
"Cannot mmap. Error = " <<
errno;
225 rgn_ptr =
static_cast<char*
>(ptr);
279 other.rgn_ptr =
nullptr;
307 other.rgn_ptr =
nullptr;
480 return o <<
"MapArena:\n"
481 <<
" rgn_ptr = " <<
static_cast<void*
>(s.
rgn_ptr) <<
'\n'
482 <<
" end_ = " << s.
end_ <<
'\n'
483 <<
" rgn_size = " << s.
rgn_size <<
'\n'
484 <<
" size = " << s.
size() <<
'\n'
485 <<
" capacity = " << s.
capacity() <<
'\n'
486 <<
" avail = " << s.
avail();
Exception handling system with formatted messages for Aleph-w.
#define ah_runtime_error_unless(C)
Throws std::runtime_error if condition does NOT hold.
Memory-mapped file arena allocator.
size_type size() const noexcept
Get the total committed (allocated) size.
char * iterator
Iterator type for traversing allocated memory.
MapArena() noexcept=default
Default constructor - creates an uninitialized arena.
size_type capacity() const noexcept
Get the current capacity (mapped region size).
char * base() const noexcept
Get the base address of the mapped region.
MapArena & operator=(MapArena &&other) noexcept
Move assignment operator.
void init_and_erase(const std::string &file_path_name)
Initialize and erase any existing data.
void init(const std::string &file_path_name, void *addr=nullptr)
Initialize the arena with a backing file.
int file_descriptor() const noexcept
Get the file descriptor.
bool remap(const size_t sz)
Remap the memory region to accommodate more allocations.
friend std::ostream & operator<<(std::ostream &o, const MapArena &s)
Output operator for debugging.
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.
const_iterator begin() const noexcept
Get const iterator to the beginning.
const_iterator end() const noexcept
Get const iterator past the last allocated byte.
MapArena(const std::string &file_path_name)
Construct an arena with a backing file.
bool is_initialized() const noexcept
Check if the arena has been initialized.
int fd
File descriptor for the backing file.
~MapArena()
Destructor - unmaps memory and closes file.
size_t end_
Allocation offset from rgn_ptr.
size_t size_type
Size type for memory sizes.
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.
void * mapped_addr() const noexcept
Get the mapped memory address.
iterator begin() noexcept
Get iterator to the beginning of allocated memory.
const char * const_iterator
Const iterator type.
void sync() noexcept
Ensure data is persisted to disk.
size_t rgn_size
Current mapped region size.
char * rgn_ptr
Pointer to the mapped memory region.
Main namespace for Aleph-w library functions.
DynList< T > maps(const C &c, Op op)
Classic map operation.