[Ltrace-devel] [RFC 1/5] vect: Fix vect_reserve for large count
edgar.iglesias at gmail.com
edgar.iglesias at gmail.com
Fri Oct 5 13:36:26 UTC 2012
From: "Edgar E. Iglesias" <edgar at axis.com>
Use a simple over-allocation scheme that allocates 4 slots
for future growth.
Signed-off-by: Edgar E. Iglesias <edgar at axis.com>
---
vect.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/vect.c b/vect.c
index 7dae847..b01b70e 100644
--- a/vect.c
+++ b/vect.c
@@ -82,7 +82,8 @@ int
vect_reserve(struct vect *vec, size_t count)
{
if (count > vec->allocated) {
- size_t na = vec->allocated != 0 ? 2 * vec->allocated : 4;
+ /* Allocate 4 extra slots for growth. */
+ size_t na = count + 4;
void *n = realloc(vec->data, na * vec->elt_size);
if (n == NULL)
return -1;
--
1.7.8.6
More information about the Ltrace-devel
mailing list