How can I find the length of a given GArray?

2019-04-28 14:41发布

问题:

I have a GArray of GValue (all non-zero) which has been allocated at runtime with g_array_append_val. I wonder how can I find out what's the index of the last element, or more precisely how many elements does the array hold. Code like


for (length=0;g_value_get_int(&g_array_index(array, GValue, length)); length++);
return length

would fail with an out of bounds.

回答1:

It doesn't seem to be well-documented, but the number of the elements in the array is stored in the field array->len.



标签: c glib