From fc450ffb9cc44781fa50b789dd5394e3f8937b36 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 17 Oct 2015 19:58:00 -0700 Subject: New function chk_manage_vec. This function manages a dynamic array using only the filled size as input, while minimizing reallocations. The allocated size is implicitly always the next power of two at or above the filled size. * lib.c (next_pow_two): New static function. (chk_manage_vec): New function. * lib.h (chk_manage_vec): Declared. --- lib.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib.h') diff --git a/lib.h b/lib.h index 0d0228d4..f2ce5f9b 100644 --- a/lib.h +++ b/lib.h @@ -535,6 +535,8 @@ mem_t *chk_calloc(size_t n, size_t size); mem_t *chk_realloc(mem_t *, size_t size); mem_t *chk_grow_vec(mem_t *old, size_t oldelems, size_t newelems, size_t elsize); +mem_t *chk_manage_vec(mem_t *old, size_t oldfilled, size_t newfilled, + size_t elsize, mem_t *fillval); wchar_t *chk_wmalloc(size_t nwchar); wchar_t *chk_strdup(const wchar_t *str); char *chk_strdup_utf8(const char *str); -- cgit v1.2.3