How can I find the length of a given GArray?

雨燕双飞 提交于 2020-01-02 02:43:32

问题


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.



来源:https://stackoverflow.com/questions/33836247/how-can-i-find-the-length-of-a-given-garray

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!