[Cogl] [PATCH] Adds internal CoglMemoryStack utility API

Neil Roberts neil at linux.intel.com
Fri Apr 20 05:42:12 PDT 2012


Robert Bragg <robert at sixbynine.org> writes:

> + * We currently use this in our tesselator which has to allocate
> + * lots of small vertex, edge and face structures but once tesselation
> + * has been finished we just want to free the whole lot in one go.

It isn't used in the tesselator yet, right?

> +  guint8 *data;

guint8 is banned!

> +typedef struct _CoglMemoryStack
> +{
> +  GQueue *sub_stacks;

Maybe it doesn't matter much, but it might be nicer to use a COGL_TAILQ
here instead of a GQueue. The CoglMemorySubStacks will always be in a
list so it seems to make sense to use an embedded list node. Or at the
very least this might as well use an inline GQueue instead of a pointer
to a separately allocated GQueue.

If we allocate the data for the sub stack directly in the same
allocation as the CoglMemorySubStack struct (ie, over-allocate the
struct) then we could avoid using glib's slice allocator altogether.
That might be nice if we eventually want to use this as a basis for a
replacement for using GSlice.

> +  _cogl_memory_stack_add_sub_stack (stack, MAX (sub_stack->bytes,
>     bytes) * 2);

It might be nice to ensure that the sub stack size is always a power of
two. Not sure if that really matters though.

It took me a while to understand in what situations the rest of the sub
stacks will be searched. Maybe it could do with a comment above the for
loop to say this will only be searched after a rewind and in that case
all of the subsequent stacks will be empty.

Regards,
- Neil


More information about the Cogl mailing list