File tree Expand file tree Collapse file tree 3 files changed +69
-0
lines changed Expand file tree Collapse file tree 3 files changed +69
-0
lines changed Original file line number Diff line number Diff line change 38
38
//!
39
39
//! assert!(res.is_ok());
40
40
//! ```
41
+ //!
42
+ //! # Array block initialization
43
+ //!
44
+ //! You can create a static variable that contains an array of memory blocks and give all the blocks
45
+ //! to the `ArcPool`. This requires an intermediate `const` value as shown below:
46
+ //!
47
+ //! ```
48
+ //! use heapless::{arc_pool, pool::arc::ArcBlock};
49
+ //!
50
+ //! arc_pool!(P: u128);
51
+ //!
52
+ //! const POOL_CAPACITY: usize = 8;
53
+ //!
54
+ //! let blocks: &'static mut [ArcBlock<u128>] = {
55
+ //! const BLOCK: ArcBlock<u128> = ArcBlock::new(); // <=
56
+ //! static mut BLOCKS: [ArcBlock<u128>; POOL_CAPACITY] = [BLOCK; POOL_CAPACITY];
57
+ //! unsafe { &mut BLOCKS }
58
+ //! };
59
+ //!
60
+ //! for block in blocks {
61
+ //! P.manage(block);
62
+ //! }
63
+ //! ```
41
64
42
65
// reference counting logic is based on version 1.63.0 of the Rust standard library (`alloc` crate)
43
66
// which is licensed under 'MIT or APACHE-2.0'
Original file line number Diff line number Diff line change 53
53
//!
54
54
//! assert!(res.is_ok());
55
55
//! ```
56
+ //!
57
+ //! # Array block initialization
58
+ //!
59
+ //! You can create a static variable that contains an array of memory blocks and give all the blocks
60
+ //! to the `BoxPool`. This requires an intermediate `const` value as shown below:
61
+ //!
62
+ //! ```
63
+ //! use heapless::{box_pool, pool::boxed::BoxBlock};
64
+ //!
65
+ //! box_pool!(P: u128);
66
+ //!
67
+ //! const POOL_CAPACITY: usize = 8;
68
+ //!
69
+ //! let blocks: &'static mut [BoxBlock<u128>] = {
70
+ //! const BLOCK: BoxBlock<u128> = BoxBlock::new(); // <=
71
+ //! static mut BLOCKS: [BoxBlock<u128>; POOL_CAPACITY] = [BLOCK; POOL_CAPACITY];
72
+ //! unsafe { &mut BLOCKS }
73
+ //! };
74
+ //!
75
+ //! for block in blocks {
76
+ //! P.manage(block);
77
+ //! }
78
+ //! ```
56
79
57
80
use core:: {
58
81
fmt,
Original file line number Diff line number Diff line change 39
39
//!
40
40
//! assert!(res.is_some());
41
41
//! ```
42
+ //!
43
+ //! # Array block initialization
44
+ //!
45
+ //! You can create a static variable that contains an array of memory blocks and give all the blocks
46
+ //! to the `ObjectPool`. This requires an intermediate `const` value as shown below:
47
+ //!
48
+ //! ```
49
+ //! use heapless::{object_pool, pool::object::ObjectBlock};
50
+ //!
51
+ //! object_pool!(P: [u8; 128]);
52
+ //!
53
+ //! const POOL_CAPACITY: usize = 8;
54
+ //!
55
+ //! let blocks: &'static mut [ObjectBlock<[u8; 128]>] = {
56
+ //! const BLOCK: ObjectBlock<[u8; 128]> = ObjectBlock::new([0; 128]); // <=
57
+ //! static mut BLOCKS: [ObjectBlock<[u8; 128]>; POOL_CAPACITY] = [BLOCK; POOL_CAPACITY];
58
+ //! unsafe { &mut BLOCKS }
59
+ //! };
60
+ //!
61
+ //! for block in blocks {
62
+ //! P.manage(block);
63
+ //! }
64
+ //! ```
42
65
43
66
use core:: {
44
67
cmp:: Ordering ,
You can’t perform that action at this time.
0 commit comments