A platform-agnostic memory allocator designed for block allocators.
The PS Vita provides a kernel API that allows to allocate memory blocks in the
console RAM. However, the kernel will only ever allocate blocks of 4kB-aligned
memory. While the VitaSDK newlib
port uses a 32MB sized heap in a single
memory block, it is not the most efficient to do so considering there is a
proper allocator available.
The deblockator
allocator relies on another allocator to obtain data blocks, and
then uses a classic linked-list approachs to provide smaller memory chunks within
those blocks. This allows growing a virtually infinite heap without needing to
preallocate a large block on startup.
Add this crate to Cargo.toml
:
[dependencies.deblockator]
git = "https://github.com/vita-rust/deblockator"
You'll need to have the armv7-vita-eabihf
target specification in your
$RUST_TARGET_PATH
. If you don't have it, you can find in its dedicated
git repository.
When compiling for the PS Vita, use the Vitallocator
struct from
the vitallocator
crate
and wrap it within the Deblockator
struct:
#![feature(global_allocator)]
extern crate deblockator;
extern crate vitallocator;
use deblockator::Deblockator;
use vitallocator::Vitallocator;
#[global_allocator]
static ALLOC: Deblockator = Deblockator::new(Vitallocator::new());
Compiling to the PS Vita requires the psp2-sys
crate.
- Philipp Oppermann for the
Writing an OS in Rust, in particular the Kernel Heap section,
as well as the
linked_list_allocator
crate this implementation is derived from.