Skip to content

UnknownUser03393/libdirect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

directcore

Zero-overhead cross-platform direct memory abstraction for C++.

Designed as a low-level memory backend for high-level language bindings.


Features

  • malloc-backed buffers
  • mmap-backed file mapping
  • move-only ownership (no accidental copies)
  • RAII-based lifetime management
  • cross-platform (Linux / Windows)

Usage

Header-only. #include "direct.hpp" is enough.

#include <iostream>
#include "direct.hpp"

int main() {
    // heap allocate
    auto mem = direct<int>::alloc(MB(4));
    mem[0] = 114;
    mem[1] = 514;

    std::cout << "heap: "
              << mem[0] << ", "
              << mem[1] << "\n";

    // file map
    auto mapped = direct<int>::map_file("demo.bin", MB(4));
    mapped[0] = 42;
    mapped[1] = 99;

    std::cout << "mmap: "
              << mapped[0] << ", "
              << mapped[1] << "\n";

    // ownership transfer (no copy)
    auto moved = std::move(mapped);

    std::cout << "moved: "
              << moved[0] << ", "
              << moved[1] << "\n";

    std::cout << "old valid? "
              << (mapped ? "yes" : "no") << "\n";

    // (optional) implicit release
    moved.release();

    std::cout << "released? "
              << (moved ? "no" : "yes") << "\n";
}

License

MIT License

About

Multilanguage Memory Management Library.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors