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
use crate::;
/// A reasonably safe implementation of `alloc`.
///
/// Allocates a buffer of `size` bytes and returns a pointer to it. The buffer is
/// aligned to [`crate::HEADER_SIZE`] (16) bytes and is **not** initialized. `alloc(0)`
/// succeeds and returns a valid pointer to a zero-sized buffer.
///
/// Every returned pointer, including the zero-sized case, must eventually be released
/// with [`crate::free`] or [`crate::realloc`]; otherwise the allocation leaks.
///
/// # Errors
/// - `Err(ArithmeticError)` on integer overflow.
/// - `Err(LayoutError)` if the computed layout is invalid.
/// - `Err(OutOfMemory)` if the underlying allocator returns a null pointer.