Function data_model::vec_with_array_field
source · pub fn vec_with_array_field<T: Default, F>(count: usize) -> Vec<T>
Expand description
The kernel API has many structs that resemble the following Foo
structure:
ⓘ
#[repr(C)]
struct Foo {
some_data: u32,
entries: __IncompleteArrayField<__u32>,
}
In order to allocate such a structure, size_of::<Foo>()
would be too small because it would
not include any space for entries
. To make the allocation large enough while still being
aligned for Foo
, a Vec<Foo>
is created. Only the first element of Vec<Foo>
would actually
be used as a Foo
. The remaining memory in the Vec<Foo>
is for entries
, which must be
contiguous with Foo
. This function is used to make the Vec<Foo>
with enough space for
count
entries.