> Can we do something similar in pure C without using that lib? Some
> simple example code?
I can do nothing with pure C :-P
Here is the code from glib/glib/garray.c:
static void
g_array_maybe_expand (GRealArray *array,
gint len)
{
guint want_alloc = g_array_elt_len (array, array->len + len +
array->zero_terminated);
if (want_alloc > array->alloc)
{
want_alloc = g_nearest_pow (want_alloc);
want_alloc = MAX (want_alloc, MIN_ARRAY_SIZE);
array->data = g_realloc (array->data, want_alloc);
#ifdef ENABLE_GC_FRIENDLY
memset (array->data + array->alloc, 0, want_alloc - array->alloc);
#endif /* ENABLE_GC_FRIENDLY */
array->alloc = want_alloc;
}
}