maug
Quick and dirty C mini-augmentation library.
Loading...
Searching...
No Matches
MDATA_VECTOR Struct Reference

A vector of uniformly-sized objects, stored contiguously. More...

#include <mdata.h>

Data Fields

uint8_t flags
 
MAUG_MHANDLE data_h
 Handle for allocated items (unlocked).
 
uint8_t * data_bytes
 Handle for allocated items (locked).
 
size_t ct_max
 Maximum number of items currently allocated for.
 
size_t ct
 Maximum number of items actually used.
 
size_t ct_step
 Number of items added when more space is needed.
 
size_t item_sz
 Size, in bytes, of each item.
 
ssize_t locks
 Lock count, if MDATA_VECTOR_FLAG_REFCOUNT is enabled.
 

Related Symbols

(Note that these are not member symbols.)

#define MDATA_VECTOR_FLAG_REFCOUNT   0x01
 Flag for MDATA_VECTOR::flags indicating that vector may uses reference counting for locking.
 
#define MDATA_VECTOR_INIT_SZ   10
 Default initial value for MDATA_VECTOR::ct_max.
 
#define MDATA_VECTOR_INIT_STEP_SZ   10
 Default initial value for MDATA_VECTOR::ct_step.
 
ssize_t mdata_vector_append (struct MDATA_VECTOR *v, const void *item, size_t item_sz)
 Append an item to the specified vector.
 
MERROR_RETVAL mdata_vector_remove (struct MDATA_VECTOR *v, size_t idx)
 Remove item at the given index, shifting subsequent items up by 1.
 
void * mdata_vector_get_void (struct MDATA_VECTOR *v, size_t idx)
 Get a generic pointer to an item in the MDATA_VECTOR.
 
#define mdata_vector_lock(v)
 Lock the vector. This should be done when items from the vector are actively being referenced, so the system is not allowed to move the vector's data allocation block.
 
#define mdata_vector_unlock(v)
 Unlock the vector so items may be added and removed.
 
#define mdata_vector_ct(v)
 Number of items of MDATA_VECTOR::item_sz bytes actively stored in this vector.
 
#define mdata_vector_sz(v)
 Number of bytes of heap memory occupied by this vector.
 
#define mdata_vector_fill(v, ct_new, sz)
 Allocate and mark the new slots as active.
 

Detailed Description

A vector of uniformly-sized objects, stored contiguously.

May be initialized with mdata_vector_alloc() before use, but mdata_vector_append() will attempt to do this automatically.

Warning
Internal details may be subject to change, and should be accessed with wrapper macros and convenience functions.

Field Documentation

◆ item_sz

size_t MDATA_VECTOR::item_sz

Size, in bytes, of each item.

Warning
Attempting to store items with a different size will fail!

The documentation for this struct was generated from the following file: