44 word length_increment,
50 uword old_alloc_bytes, new_alloc_bytes;
55 data_bytes += header_bytes;
61 memset (
new, 0, data_bytes);
62 v =
new + header_bytes;
63 _vec_len (v) = length_increment;
67 vh->
len += length_increment;
68 old = v - header_bytes;
76 if (data_bytes <= old_alloc_bytes)
79 new_alloc_bytes = (old_alloc_bytes * 3) / 2;
80 if (new_alloc_bytes < data_bytes)
81 new_alloc_bytes = data_bytes;
87 clib_panic (
"vec_resize fails, length increment %d, data bytes %d, alignment %d",
88 length_increment, data_bytes, data_align);
98 memset (v + old_alloc_bytes, 0, new_alloc_bytes - old_alloc_bytes);
100 return v + header_bytes;
112 void main (
int argc,
char * argv[])
114 word n = atoi (argv[1]);
121 FOO * foos = vec_init (FOO, 10), * f;
127 for (i = 0; i < n; i++)
131 f->x = 2*
i; f->y = 3*
i; f->z = 4*
i;
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
sll srl srl sll sra u16x4 i
void * vec_resize_allocate_memory(void *v, word length_increment, uword data_bytes, uword header_bytes, uword data_align)
Low-level resize allocation function, usually not called directly.
always_inline void * clib_mem_alloc_aligned_at_offset(uword size, uword align, uword align_offset)
always_inline void clib_mem_free(void *p)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
add_epi add_epi sub_epi sub_epi adds_epu subs_epu i16x8 y
uword clib_mem_is_vec_h(void *v, uword header_bytes)
Predicate function, says whether the supplied vector is a clib heap object (general version)...
always_inline uword clib_mem_size(void *p)
#define vec_insert(V, N, M)
Insert N vector elements starting at element M, initialize new elements to zero (no header...
#define vec_free(V)
Free vector's memory (no header).
#define clib_memcpy(a, b, c)
#define vec_delete(V, N, M)
Delete N elements starting at element M.
always_inline uword clib_mem_is_heap_object(void *p)
always_inline void * vec_header(void *v, uword header_bytes)
Find a user vector header.
#define clib_panic(format, args...)
always_inline uword vec_header_bytes(uword header_bytes)
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".