Skip to content

Instantly share code, notes, and snippets.

@jorendorff
Last active January 30, 2018 16:00
Show Gist options
  • Save jorendorff/9d3f9fdf0b34c671fe4fe937ded0976b to your computer and use it in GitHub Desktop.
Save jorendorff/9d3f9fdf0b34c671fe4fe937ded0976b to your computer and use it in GitHub Desktop.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment