From 10e8e2017c8193b784f30a2aeb625f6eb0d3e965 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Wed, 8 Sep 2021 09:05:16 +0200 Subject: Added init_with_capacity(). --- include/stc/cstack.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include/stc/cstack.h') diff --git a/include/stc/cstack.h b/include/stc/cstack.h index f68a01d7..448b6c2f 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -39,6 +39,11 @@ typedef i_valraw cx_rawvalue_t; STC_INLINE Self cx_memb(_init)(void) { return (Self){0, 0, 0}; } +STC_INLINE Self cx_memb(_init_with_capacity)(size_t cap) { + Self out = {(cx_value_t *) c_malloc(cap*sizeof(cx_value_t)), 0, cap}; + return out; +} + STC_INLINE void cx_memb(_clear)(Self* self) { size_t i = self->size; self->size = 0; while (i--) i_valdel(&self->data[i]); -- cgit v1.2.3