Module heapless::pool

source ·
Expand description

Memory and object pools

§Target support

This module / API is only available on these compilation targets:

  • ARM architectures which instruction set include the LDREX, CLREX and STREX instructions, e.g. thumbv7m-none-eabi but not thumbv6m-none-eabi
  • 32-bit x86, e.g. i686-unknown-linux-gnu

§Benchmarks

  • compilation settings

    • codegen-units = 1
    • lto = 'fat'
    • opt-level = 'z'
  • compilation target: thumbv7em-none-eabihf

  • CPU: ARM Cortex-M4F

  • test program:

use heapless::box_pool;

box_pool!(P: ()); // or `arc_pool!` or `object_pool!`

bkpt();
let res = P.alloc(());
bkpt();

if let Ok(boxed) = res {
    bkpt();
    drop(boxed);
    bkpt();
}
  • measurement method: the cycle counter (CYCCNT) register was sampled each time a breakpoint (bkpt) was hit. the difference between the “after” and the “before” value of CYCCNT yields the execution time in clock cycles.
APIclock cycles
BoxPool::alloc23
pool::boxed::Box::drop23
ArcPool::alloc28
pool::arc::Arc::drop59
ObjectPool::request23
pool::object::Object::drop23

Note that the execution time won’t include T’s initialization nor T’s destructor which will be present in the general case for Box and Arc.

Modules§

  • std::sync::Arc-like API on top of a lock-free memory pool
  • std::boxed::Box-like API on top of a lock-free memory pool
  • Object pool API