safe-allocator-api
A safe wrapper around the allocator_api
's Allocator trait.
This crate provides a wrapper around the returned results, ensuring that any allocated memory is automatically dropped when its lifetime expires.
Features
- Safe wrapper around raw allocations with known layout
- Automatic deallocation when values go out of scope
- Support for custom allocators
- Zero-initialization options
- Grow and shrink operations with proper error handling
- Thread-safe (implements
Send
andSync
)- Actual thread safety depends on safety of the allocator used internally, tread wisely.
In my case I wrote this crate to have a 'safe' way to make aligned allocations 😉.
Usage
Add this to your Cargo.toml
:
[]
= "0.1.0"
Examples
Basic Allocation
use *;
use RawAlloc;
Zero-Initialized Memory
use *;
use RawAlloc;
Growing and Shrinking Allocations
use *;
use RawAlloc;
Custom Allocators
use *;
use RawAlloc;
Error Handling
Operations will return AllocError in the following cases:
- The allocator reports an error
- Attempting to allocate zero bytes
- Growing to a smaller size
- Shrinking to a larger size
i.e. This is a thin wrapper around the existing API, so we reuse error types from std.
Crate Features
std
[default]: Builds againststd
nightly
: Enables the nightlyallocator_api
feature
Development
For information on how to work with this codebase, see README-DEV.MD.
License
Licensed under MIT.
Learn more about Reloaded's general choice of licensing for projects..