1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
use ;
use crate::;
/// Minimum block size in bytes. Read the documentation of the data structures
/// used for this allocator to understand why it has this value. Specifically,
/// see [`Header<T>`], [`Block`], [`Region`], [`crate::list::LinkedList<T>`] and
/// especially [`FreeListNode`].
pub const MIN_BLOCK_SIZE: usize = ;
/// Block header size in bytes. See [`Header<T>`] and [`Block`].
pub const BLOCK_HEADER_SIZE: usize = ;
/// Memory block specific data. All headers are also linked list nodes, see
/// [`Header<T>`]. In this case, a complete block header would be
/// [`crate::list::Node<Block>`], also known as [`Header<Block>`]. Here's a
/// graphical representation of how it looks like in memory:
///
/// ```text
/// +----------------------------+ <----------------------+
/// | pointer to next block | <------+ |
/// +----------------------------+ | Pointer<Node<Block>> |
/// | pointer to prev block | <------+ |
/// +----------------------------+ |
/// | pointer to block region | <------+ |
/// +----------------------------+ | | <Node<Block>>
/// | block size | | |
/// +----------------------------+ | Block |
/// | is free flag (1 byte) | | |
/// +----------------------------+ | |
/// | padding (struct alignment) | <------+ |
/// +----------------------------+ <----------------------+
/// | Block content | <------+
/// | ... | |
/// | ... | | Addressable content
/// | ... | |
/// | ... | <------+
/// +----------------------------+
/// ```
///
/// Note that the order of struct fields doesn't matter, this is just an
/// example. The compiler might reorder the fields in a different way unless we
/// use [`repr`](https://doc.rust-lang.org/nomicon/repr-rust.html), but we
/// never assume any specific order on the struct fields, so we don't need it.
///
/// The block content is where the allocator users write their data. However,
/// the pointer that we provide them with **MAY NOT** point exactly to the first
/// address of the block content. That's because we have to support alignments
/// of any size (any power of 2), so we need to make sure that the pointers we
/// return satisfy the required alignment constraints. See [`crate::alignment`]
/// for a detailed explanation. Also note that if a block is free (not
/// currently used by the caller) we take advantage of the fact that we can
/// put anything we want in the block content. See [`crate::freelist`].
pub