Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find the length of a given GArray?

Tags:

c

glib

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.

like image 802
Reimundo Heluani Avatar asked Nov 20 '15 21:11

Reimundo Heluani


1 Answers

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

It's described here.

like image 171
user253751 Avatar answered Oct 23 '22 20:10

user253751