A custom allocator changes how heap memory is allocated for a particular need. Rust normally uses a system-backed global allocator. Use `GlobalAlloc` to replace it program-wide, or the `Allocator` API to select an allocator for individual data structures. At the time described here, `GlobalAlloc` is stable; the `Allocator` API requires nightly Rust. section 5.8
Consider a custom allocator when the default cannot meet a specific requirement:
- Constrained embedded systems or performance-critical allocation. section 5.8
- Protected memory for sensitive data, using operating-system memory locking and access controls. section 5.8 section 5.8.2
- Special allocation across library or language boundaries, or application-level memory-usage tracking. section 5.8
Page-aligned protected memory
A protected-memory allocator rounds the requested size to a page boundary, adds a page before and after the active region, and allocates the whole area with `posix_memalign()` on UNIX or `VirtualAlloc()` on Windows. It returns the active region rather than the surrounding pages. Deallocation must account for those extra pages: the shown `deallocate()` code moves back to the start of the allocation and restores access to the fore and aft regions. section 5.8.2
The layout distinguishes the returned active region from the surrounding fore and aft regions. section 5.8.2
Keep nightly-only allocator code behind a crate feature when publishing a crate that also supports stable Rust. A protected-memory module can be included in documentation while excluded from doctests unless the nightly feature is enabled, and marked as nightly-only in generated documentation. Prefer the default allocator unless a concrete constraint justifies the added implementation and platform-specific work. section 3.7.2 section 5.8 section 5.8.2
