Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xoofx/varena
Varena is a .NET library that provides a fast and lightweight arena allocator using virtual memory.
https://github.com/xoofx/varena
allocator arena-allocator dotnet virtual-memory
Last synced: 8 days ago
JSON representation
Varena is a .NET library that provides a fast and lightweight arena allocator using virtual memory.
- Host: GitHub
- URL: https://github.com/xoofx/varena
- Owner: xoofx
- License: bsd-2-clause
- Created: 2022-09-10T08:13:28.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-17T14:05:20.000Z (8 months ago)
- Last Synced: 2024-06-09T12:45:11.938Z (5 months ago)
- Topics: allocator, arena-allocator, dotnet, virtual-memory
- Language: C#
- Homepage:
- Size: 83 KB
- Stars: 155
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
# Varena [![ci](https://github.com/xoofx/Varena/actions/workflows/ci.yml/badge.svg)](https://github.com/xoofx/Varena/actions/workflows/ci.yml) [![Coverage Status](https://coveralls.io/repos/github/xoofx/Varena/badge.svg?branch=main)](https://coveralls.io/github/xoofx/Varena?branch=main) [![NuGet](https://img.shields.io/nuget/v/Varena.svg)](https://www.nuget.org/packages/Varena/)
Varena is a .NET library that provides a fast and lightweight arena allocator using virtual memory.
## Features- Create very large continuous byte buffers and arrays (e.g 1 TiB) of data without committing the virtual memory to the physical memory.
- Only use the memory that is allocated, not the total capacity reserved!
- Fast bump allocator with a commit per block (default is 64 KiB of memory committed)
- Use `VirtualBuffer` for manipulating bytes.
- Use `VirtualArray` for manipulating a dynamic array of unmanaged data.
- Compatible with `.NET6.0+` and on all platforms (Windows, Linux, macOS)## Usage
```csharp
using Varena;// The manager keeps track of all created arenas (buffers, arrays)
using var manager = new VirtualArenaManager();// Create a byte buffer and reserve 1 GiB of continuous memory (but not yet allocated)
var arena1 = manager.CreateBuffer("Arena1", 1 << 30);
// Allocate 1024 bytes -> The arena commits a block 64 KiB of memory (configurable)
var span = arena1.AllocateRange(1024);
span[0] = 1;
// Allocate 2048 bytes -> The arena keeps allocating in the previous commit block of 64 KiB
var span2 = arena1.AllocateRange(2048);
span2[0] = 1;// Create a data array and reserve 1 MiB of continuous memory (but not yet allocated)
var arena2 = manager.CreateArray("Arena2", 1 << 20);
// Allocate sizeof(Guid) * 1024 bytes -> The arena commits a block 64 KiB of memory (configurable)
var span3 = arena2.AllocateRange(1024);
span3[0] = Guid.NewGuid();
```### Documentation
You will find more details about how to use Varena in this [user guide](https://github.com/xoofx/Varena/blob/main/doc/readme.md).
## License
This software is released under the [BSD-Clause 2 license](https://opensource.org/licenses/BSD-2-Clause).
## Author
Alexandre Mutel aka [xoofx](https://xoofx.github.io).