Crates.io | reloaded-memory-buffers |
lib.rs | reloaded-memory-buffers |
version | 4.1.0 |
source | src |
created_at | 2023-07-24 03:03:55.250379 |
updated_at | 2023-12-30 13:31:10.093654 |
description | Shared, Concurrent, Permanent Memory Allocator tied to Process Lifetime |
homepage | |
repository | https://github.com/Reloaded-Project/Reloaded.Memory.Buffers |
max_upload_size | |
id | 924185 |
size | 218,267 |
Reloaded.Memory.Buffers
is a library for allocating memory between a given minimum and maximum memory address, for C# and Rust.
With the following properties:
Note: Rust/C port also work with FreeBSD (untested), and has partial (limited) Android support.
For full documentation, please see the Wiki.
These are just examples:
!!! info "The library provides a simple high level API to use."
!!! info "See Wiki for Rust usage"
Gets a buffer where you can allocate 4096 bytes in first 2GiB of address space.
var settings = new BufferSearchSettings()
{
MinAddress = 0,
MaxAddress = int.MaxValue,
Size = 4096
};
// Make sure to dispose, so lock gets released.
using var item = Buffers.GetBuffer(settings);
// Write some data, get pointer back.
var ptr = item->Append(data);
Gets a buffer where 4096 bytes written will be within 2GiB of 0x140000000.
var settings = BufferSearchSettings.FromProximity(int.MaxValue, (nuint)0x140000000, 4096);
// Make sure to dispose, so lock gets released.
using var item = Buffers.GetBuffer(settings);
// Write some data, get pointer back.
var ptr = item->Append(data);
Allows you to temporarily allocate memory within a specific address range and size constraints.
// Arrange
var settings = new BufferAllocatorSettings()
{
MinAddress = 0,
MaxAddress = int.MaxValue,
Size = 4096
};
using var item = Buffers.AllocatePrivateMemory(settings);
// You have allocated memory in first 2GiB of address space.
// Disposing this memory (via `using` statement) will free it.
item.BaseAddress.Should().NotBeNull();
item.Size.Should().BeGreaterOrEqualTo(settings.Size);
You can specify another process with TargetProcess = someProcess
in BufferAllocatorSettings
, but this is only supported on Windows.
std
: [Enabled by Default] Enables use of standard library.external_processes
: Support external processes (windows only).no_format
: Disables formatting code in errors, saving ~8kB of space.size_opt
: Makes cold paths optimized for size instead of optimized for speed. [Requires 'nightly' Rust]c_exports
Provides C exports for the library.If you have questions/bug reports/etc. feel free to Open an Issue.
Contributions are welcome and encouraged. Feel free to implement new features, make bug fixes or suggestions so long as they meet the quality standards set by the existing code in the repository.
For an idea as to how things are set up, see Reloaded Project Configurations.
Happy Hacking 💜