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 implementSend
orSync
(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 |
MutexGuard |
represents memory which can be used. dropping this unlocks the memory and allows it to be defragmentated. |
Pool |
|
RawPool |
|
SliceMutex |
same as |
SliceMutexGuard |
Enums
Error |
memory error codes |
TryLockError |
An enumeration of possible errors which can occur while calling the
|
Type Definitions
Result | |
TryLockResult |