Vec_new always allocates storage, vec_validate ensures that an existing 
allocation is at least a certain size, or create a new one if the pointer is 
NULL. The latter is typically used when the storage will be used as an array 
and you want to make sure it's large enough to store element N.


The other subtle difference is that you need to tell vec_new the type of the 
elements in the array (so it knows the size) whereas vec_validate can glean 
that from the type of the vector (possibly NULL) you pass in.


From: <> On Behalf Of Bly, Mike
Sent: Thursday, April 12, 2018 15:30
Subject: [vpp-dev] vec_new() vs. vec_validate()


After some digging, near as I can tell, for a new pointer to a new entity, it 
would seem that vec_new() is pretty much providing the same results as 
vec_validate(), albeit, with one less memset(bob, o, sizeof(*bob)) being 
performed. However, I see a 10:1 usage (preference?) of vec_validate() vs. 
vec_new() in the existing vpp src, so I was hoping someone could share some of 
the "why" here as to when one should use either.


Reply via email to