Skip to content

miny: Extra padding size #4

@1e1001

Description

@1e1001

As suggested in #1:

a const parameter that adds extra bytes of inline space beyond one pointer's worth.

Since I kinda wanna wait until I merge #2 before working on code (to fear of rebase/merge hell), I'll just write down some notes of this and implement it later:

Making it a (hopefully) non-breaking change

My idea is to change the definiton of Miny from:

struct Miny<T: ?Sized> {
  meta: Metadata<T>,
  data: MaybeUninit<*mut ()>,
  marker: PhantomData<T>,
}

to:

struct Miny<T: ?Sized, const S: usize = 1> {
  meta: Metadata<T>,
  data: Data<S>,
  marker: PhantomData<T>,
}
union Data<const S: usize> {
  pointer: *mut (),
  padding: MaybeUninit<[*mut (); S]>,
}

Where S (final name t.b.d.) represents the size of the inline section (in pointer-sizes, to keep things more consistent across platforms), usable without any extra nightly features.

Splitting out the Data would also probably make it easier to delineate safe/unsafe code, as most of the unsafe is just in accessing the combination pointer+value.

Main use for this is as just a small optimization if you know what kind of values you have, e.g. using a Miny<dyn Any, 3> for storing String and Vec -likes inline.

An alternative method could be using a type-generic for referencing the size of a specific type, but I feel like that would break more easily.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions