Overview
simple_mmap provides SCOOP-compatible memory-mapped file operations for Eiffel applications. It wraps the Win32 file mapping API through a clean C interface, enabling efficient file I/O and shared memory without threading complications.
The library supports file-backed mappings, anonymous mappings, and shared memory segments for inter-process communication, with type-safe read/write operations for bytes, integers, strings, and raw byte arrays.
Part of the simple_* ecosystem of focused, single-purpose Eiffel libraries.
Quick Start
Installation
<library name="simple_mmap" location="$SIMPLE_EIFFEL/simple_mmap/simple_mmap.ecf"/>
File Mapping
local
mmap: SIMPLE_MMAP
do
-- Map an existing file
create mmap.make_from_file ("data.bin", mmap.Access_read_write)
if mmap.is_valid then
-- Read/write at specific offsets
mmap.write_string (0, "Hello, World!")
print (mmap.read_string (0))
mmap.close
end
end
Anonymous Mapping
local
mmap: SIMPLE_MMAP
do
-- Create memory-only mapping (no file)
create mmap.make_anonymous (4096) -- 4KB
if mmap.is_valid then
mmap.write_integer (0, 42)
print (mmap.read_integer (0)) -- 42
mmap.close
end
end
Shared Memory (IPC)
local
mmap: SIMPLE_MMAP
do
-- Create named shared memory accessible from other processes
create mmap.make_shared ("MySharedMem", 1024)
if mmap.is_valid then
mmap.write_string (0, "Shared data")
mmap.close
end
end
Features
File Mapping
Map entire files or file regions into memory
Anonymous Mapping
Create memory-backed mappings without files
Shared Memory
Named mappings for inter-process communication
Type-Safe I/O
Read/write bytes, integers, strings, and byte arrays
Access Modes
| Mode | Description |
|---|---|
Access_read | Read-only access |
Access_read_write | Read and write access |
API Reference
Creation
| Feature | Description |
|---|---|
make_from_file (path, access) | Create mapping from file |
make_anonymous (size) | Create memory-only mapping |
make_shared (name, size) | Create named shared memory |
Reading Data
| Feature | Description |
|---|---|
read_byte (offset) | Read single byte at offset |
read_integer (offset) | Read 32-bit integer at offset |
read_string (offset) | Read null-terminated string |
read_bytes (offset, count) | Read array of bytes |
Writing Data
| Feature | Description |
|---|---|
write_byte (offset, value) | Write single byte |
write_integer (offset, value) | Write 32-bit integer |
write_string (offset, value) | Write null-terminated string |
write_bytes (offset, bytes) | Write array of bytes |
Status
| Feature | Description |
|---|---|
is_valid | Is the mapping valid? |
size | Size of mapped region in bytes |
close | Unmap and release resources |