Vector Types#
amongoc defines various dynamically-sized contiguous array types. These are
stamped out from a template and all follow an identical API shape. These vector
types are conventially named as xyz_vec, where xyz is the name of the
element type.
This page will document the vector type interface using a placeholder type
item_vec::T.
Warning
The vector API template is contained in a publicly-visible header, but direct use of that header is an implementation detail.
-
struct [[zero_initializable]] item_vec#
A dynamically-sized contiguous array of objects of type
T. Note that the nameitem_vecis a stand-in for an actual concrete vector type.-
type T#
The name “
T” herein acts as a stand-in for the type of the actual vector elements, which vary.
- Zero-initialized:
[[zero_initializable]]A zero-initialized vector is considered null, and holds no objects. Deleting a null vector is a no-op. A null vector cannot be resized: It must first be initialized usingitem_vec_new().
A vector type will automatically call a pre-defined destructor function on the vector elements when it is resized or deleted.
-
T *data#
A pointer to the first element of the contiguous array. The length of the pointed-to array is designated by
size.
-
mlib_allocator allocator#
The dynamic memory allocator associated with this object.
-
type T#
-
item_vec::T *item_vec_begin(item_vec vec)#
-
item_vec::T *item_vec_end(item_vec vec)#
Obtain the begin/end pointers to the dynamically-sized array managed by
vec.
-
size_t item_vec_max_size(void)#
Obtain the maximum number of objects that can be stored in an
item_vec
-
[[1]] item_vec item_vec_new(mlib_allocator alloc)#
-
[[2]] item_vec item_vec_new_n(size_t n, bool *alloc_okay, mlib_allocator alloc)#
Create a new vector of objects.
[[1]]Creates a new empty vector.[[2]]is equivalent to calling[[1]]followed by an immediateitem_vec_resize().- Parameters:
n – The number of objects to be created.
alloc_okay – A boolean that is set to
truewhen the function succeeds. Afalseresult indicates an allocation failure. This must not be null, as this is the only reliable way to detect allocation failures.alloc – The allocator for the new vector.
-
void item_vec_delete(item_vec [[transfer, nullable]] self)#
Destroy all elements are release any store associated with
self.