Axes of pointer type:
-
Validity - Information about whether the pointer is safe to dereference to begin with. Options:
- Static guarantee that the pointer is valid and non-null
- Static guarantee that it is either valid or null,
and you can dynamically check
is_null()
- No guarantees—the pointer may be any
usize
.
-
Exclusivity - Information about what the code holding the pointer may do to the memory, and what other code may do to it while the pointer exists.
- Exclusive ownership (absent lifetimes, what does this mean?)
- Exclusive ownership for some static lifetime, at the end of which it should be left uninitialized (or in some other statically specified state)
- Shared access, non-mutation guarantee
- Dynamic locking scheme
- No guarantee
-
Initialized - Information about whether the pointed-to region of memory has been initialized with a value.
- Static guarantee that it's initialized
- Static guarantee that it's uninitialized memory
- Dynamic information (a fat pointer carrying an extra bit)
- A combination of static and dynamic information about what parts are initialized (like
Vec
) - No guarantee
-
Type - Information about the type of the value (if any) stored in the pointed-to region.
- Static guarantee
- No guarantee
-
Size - The size of the region pointed to
- Static guarantee (e.g. because we statically know the type)
- Dynamic information (like slice and trait objects)
- No information
-
Alignment - Like size.