如何找到给定GArray的长度? [英] How can I find the length of a given GArray?
本文介绍了如何找到给定GArray的长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个GValue的GArray(所有非零),已在运行时使用g_array_append_val进行了分配.我想知道如何找出最后一个元素的索引,或更确切地说是数组包含多少个元素.像这样的代码
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
将失败并超出范围.
推荐答案
它似乎没有很好的文档说明,但是数组中的元素数存储在字段array->len
中.
It doesn't seem to be well-documented, but the number of the elements in the array is stored in the field array->len
.
这篇关于如何找到给定GArray的长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文