Crate defrag [] [src]

defrag: safe and low overhead memory manager for microcontrollers

This library is in the Alpha release and is subject to change

The defrag memory manager aims to bring safe heap memory management to microcontrollers. Combined with rust's excellent type system and borrow checker, creating complex applications with limited resources is easier than it has ever been before. defrag has an ultra-low overhead of only 64 bits per allocated block of memory, making allocations of any size very cheap.

The possibility of fragmentation is the primary reason that dynamic memory allocation is not used on microcontrollers. defrag, as the name implies, is able to defragment memory -- giving your embedded application power, reliability and simplicity.

How it works

The primary manager of memory is the Pool, from which the user can call Pool.alloc::<T>() or Pool.alloc_slice::<T>(len). From this they will get a Mutex<T> like object which behaves very similarily to rust's stdlib Mutex.

When the data is not locked, the underlying pool is allowed to move it in order to solve potential fragmentation issues. pool.clean() combines contiguous free blocks and pool.defrag() defragments memory. In addition, there are various strategies for utilzing freed blocks of memory.

This library is intended only for (single threaded) microcontrollers, so it's Mutex does not implement Send or Sync (it cannot be shared between threads). Depending on what kind of architectures or OS's spring up on uC rust code, this may change.

Structs

Block
Mutex

all allocated data is represented as a Mutex. When the data is unlocked, the underlying Pool is free to move it and reduce fragmentation

MutexGuard

represents memory which can be used. dropping this unlocks the memory and allows it to be defragmentated.

Pool

Pool contains a "pool" of memory which can be allocated and used

RawPool

RawPool is the private container and manager for all allocated and freed data. It handles the internals of allocation, deallocation and defragmentation.

SliceMutex

same as Mutex except wrapps a slice

SliceMutexGuard

Enums

Error

memory error codes

TryLockError

An enumeration of possible errors which can occur while calling the try_lock method.

Type Definitions

Result
TryLockResult