mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-13 12:56:15 +01:00
fb3977e9b4
The previous code consumed a larger additional amount of stack space. That is because it would allocate the temporary buffer for GValues on the stack with "g_newa (GValue, 1)" and thus the required stack space grew with the number of arguments. Granted, this is already a variadic C function, so the caller already placed that many elements on the stack. For example, on the stack there are the property names and the pointers to the arguments, which should amount to roughly O(n_args * 16) (on 64 bit, with pointers being 8 bytes large). That is not bad, because it means in the previous version the stack space would grow linear with the already used stack space. However, a GValue is an additional 24 bytes (on 64 bit), which probably more than doubles the required stack space. Let's avoid that, by allocating the temporary list on the heap after a certain threshold. This probably more than doubles the number of possible arguments before the stack overflows. Also, previously the heap allocated "params" array only grew one element per iteration. Of course, it is likely that libc anyway reallocates the buffers by growing the space exponentially. So realloc(ptr, 1) probably does not O() scale worse than doubling the buffer sizes ourselves. However, it seems clearer to keep track of the allocated sizes ourself, and only call realloc() when we determine that we are out of space. Especially because we need to update the value pointers on reallocation. Note that we now require a heap allocation both for the "params" and the "values" list. Theoretically that could be combined by using one buffer for both. But that would make the code more complicated. Now we pre-allocate buffers for 16 elements on the stack. That is (16 * (16 + 24) bytes (or 640 bytes) on the stack. I think that is still acceptable. |
||
---|---|---|
.. | ||
tests | ||
gatomicarray.c | ||
gatomicarray.h | ||
gbinding.c | ||
gbinding.h | ||
gboxed.c | ||
gboxed.h | ||
gclosure.c | ||
gclosure.h | ||
genums.c | ||
genums.h | ||
glib-enumtypes.c.template | ||
glib-enumtypes.h.template | ||
glib-genmarshal.in | ||
glib-mkenums.in | ||
glib-types.h | ||
gmarshal.c | ||
gmarshal.h | ||
gobject_gdb.py | ||
gobject_probes.d | ||
gobject_trace.h | ||
gobject-autocleanups.h | ||
gobject-query.c | ||
gobject.c | ||
gobject.h | ||
gobject.rc.in | ||
gobject.stp.in | ||
gobjectnotifyqueue.c | ||
gparam.c | ||
gparam.h | ||
gparamspecs.c | ||
gparamspecs.h | ||
gsignal.c | ||
gsignal.h | ||
gsourceclosure.c | ||
gsourceclosure.h | ||
gtype-private.h | ||
gtype.c | ||
gtype.h | ||
gtypemodule.c | ||
gtypemodule.h | ||
gtypeplugin.c | ||
gtypeplugin.h | ||
gvalue.c | ||
gvalue.h | ||
gvaluearray.c | ||
gvaluearray.h | ||
gvaluecollector.h | ||
gvaluetransform.c | ||
gvaluetypes.c | ||
gvaluetypes.h | ||
libgobject-gdb.py.in | ||
meson.build |