diff options
author | David Lamparter <equinox@opensourcerouting.org> | 2024-07-21 03:28:53 +0200 |
---|---|---|
committer | Donald Sharp <sharpd@nvidia.com> | 2024-07-31 14:08:53 +0200 |
commit | 0bf664527d003cb3670529f0609d51ce38bcf0ab (patch) | |
tree | 5f26efd0ef88e3adaeb25bf241b39b3020e8a35e /lib/vector.h | |
parent | lib: remove unused vector_copy() (diff) | |
download | frr-0bf664527d003cb3670529f0609d51ce38bcf0ab.tar.xz frr-0bf664527d003cb3670529f0609d51ce38bcf0ab.zip |
lib: allow static/pre-initialized vectors
Use alloced=0 to indicate that the array used in a vector is not in fact
dynamically allocated memory (yet).
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/vector.h')
-rw-r--r-- | lib/vector.h | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/vector.h b/lib/vector.h index 534def4f3..ae05d4d3e 100644 --- a/lib/vector.h +++ b/lib/vector.h @@ -15,9 +15,26 @@ extern "C" { /* struct for vector */ struct _vector { - unsigned int active; /* number of active slots */ - unsigned int alloced; /* number of allocated slot */ + /* active: index of last non-NULL item (+1) + * count: number of non-NULL items (+1) + * + * the two will be different if a slot is set to NULL (without pulling + * up later items in the array). Whether this happens depends on + * which vector functions are used. If no empty slots are used, the + * two fields will be identical. + * + * alloced: size of array pointed to by index. If this is 0, index + * points at a global variable rather than a malloc'd bit of memory. + * The vector code will convert to malloc'd memory if necessary to + * perform updates. + */ + unsigned int active; + unsigned int alloced; unsigned int count; + + /* whether struct _vector itself is dynamically allocated */ + bool dynamic; + void **index; /* index to data */ }; typedef struct _vector *vector; |