Typically, the header is not present. Headers allow for other
data structures to be built atop CLIB vectors.
- Users may specify the alignment for data elements via the
- vec_*_aligned macros.
+ Users may specify the alignment for first data element of a vector
+ via the vec_*_aligned macros.
- Vectors elements can be any C type e.g. (int, double, struct bar).
+ Vector elements can be any C type e.g. (int, double, struct bar).
This is also true for data types built atop vectors (e.g. heap,
pool, etc.).
- Many macros have _a variants supporting alignment of vector data
- and _h variants supporting non zero length vector headers.
- The _ha variants support both.
+ Many macros have \_a variants supporting alignment of vector elements
+ and \_h variants supporting non-zero-length vector headers. The \_ha
+ variants support both. Additionally cacheline alignment within a
+ vector element structure can be specified using the
+ CLIB_CACHE_LINE_ALIGN_MARK() macro.
Standard programming error: memorize a pointer to the ith element
of a vector then expand it. Vectors expand by 3/2, so such code
/* Typically we'll not need to resize. */
if (new_data_bytes <= clib_mem_size (p))
{
+ CLIB_MEM_UNPOISON (v, data_bytes);
vh->len += length_increment;
return v;
}
@param V (possibly NULL) pointer to a vector.
@param I vector index which will be valid upon return
@param INIT initial value (can be a complex expression!)
- @param H header size in bytes (may be zero)
- @param A alignment (may be zero)
@return V (value-result macro parameter)
*/
@param V (possibly NULL) pointer to a vector.
@param I vector index which will be valid upon return
@param INIT initial value (can be a complex expression!)
- @param H header size in bytes (may be zero)
@param A alignment (may be zero)
@return V (value-result macro parameter)
*/
@param V pointer to a vector
@param E element to add
- @param H header size in bytes (may be zero)
@param A alignment (may be zero)
@return V (value-result macro parameter)
*/
if (_v(n) > 0) \
clib_memset ((V) + _v(l) - _v(n), 0, _v(n) * sizeof ((V)[0])); \
_vec_len (V) -= _v(n); \
+ CLIB_MEM_POISON(vec_end(V), _v(n) * sizeof ((V)[0])); \
} while (0)
/** \brief Delete the element at index I
if (_vec_del_i < _vec_del_l) \
(v)[_vec_del_i] = (v)[_vec_del_l]; \
_vec_len (v) = _vec_del_l; \
+ CLIB_MEM_POISON(vec_end(v), sizeof ((v)[0])); \
} while (0)
/** \brief Append v2 after v1. Result in v1.
/** \brief Search a vector for the index of the entry that matches.
- @param v1 Pointer to a vector
- @param v2 Entry to match
+ @param v Pointer to a vector
+ @param E Entry to match
@return index of match or ~0
*/
#define vec_search(v,E) \
/** \brief Search a vector for the index of the entry that matches.
- @param v1 Pointer to a vector
- @param v2 Pointer to entry to match
+ @param v Pointer to a vector
+ @param E Pointer to entry to match
@param fn Comparison function !0 => match
@return index of match or ~0
*/