ZigZag Alloc
A collection of explicit memory allocators and collections inspired by Zig.
Prerequisites
Before building the project, ensure you have the following installed:
- Rust (latest stable version)
- A C compiler (like
gcc,clang, ormsvc) if you intend to use the C-ABI
Steps to Build
Clone the repository:
First, clone the project repository to your local machine:
Build the project:
To compile the library (including the static/dynamic libraries for C integration), run:
The compiled artifacts will be available in the target/release/ directory:
- Linux/macOS:
libzigzag_alloc.aorlibzigzag_alloc.so - Windows:
zigzag_alloc.dllandzigzag_alloc.dll.lib
Memory Management Strategies
| Allocator | Thread-Safe | Strategy | Best Use Case |
|---|---|---|---|
System |
Yes | OS native | Base allocator for long-lived structures. |
Bump |
Yes | Linear offset | Extremely fast, short-lived temp buffers. |
Arena |
No | Linked blocks | Batch-processing tasks (request/frame lifetime). |
Pool |
Yes | Free-list | Uniform objects (nodes, packets) with no fragmentation. |
Counting |
No | Wrapper | Profiling, leak detection, and memory metrics. |
Usage
In Rust
- Add the dependency
Add this to your Cargo.toml:
[]
= "^1.0.0"
Or use the cargo CLI:
- Basic Usage
The core philosophy is explicit allocation. Unlike standard collections, you must provide an allocator reference when creating a container.
use ;
use ExVec;
In C
Include the header file and link against the compiled library:
- Copy include/zigzag.h to your project.
- Compile and link with the library:
Example usage in C:
zigzag_system_t* sys = ;
zigzag_alloc_t alloc = ;
// Now you can pass 'alloc' to zigzag collections
Features
- Manual Memory Control: Explicitly pass allocators to containers.
- High-Performance SIMD: Optimized backends for x86_64 (AVX2/SSE2) and AArch64 (NEON) with SWAR fallback.
- Arena & Bump: Blazing fast linear allocation strategies.
- Pool Allocator: Fixed-size block allocation to prevent fragmentation.
- Zero-cost FFI: Seamless integration with C/C++ via stable ABI.
License
This project is licensed under the MIT license.