我怎样才能得到一个数组的C / Objective-C的大小?
问题描述:
我有这样的数组:
unsigned char* data = CGBitmapContextGetData(cgctx);
然后我试图让与的sizeof(数据)的大小,但4数据保存的信息数量较大,将返回我无义值。这不能只是4;)
then I tried to get the size with sizeof(data), but that will return me a nonsense-value of 4. data holds a big amount of information. That can't be just 4 ;)
我甚至都得到在数据[8293]信息...所以...不是4个元素。
I even get information at data[8293] ... so ... not 4 elements at all.
答
的sizeof
返回4,因为您的变量声明为一个指针,而不是C数组( char数据[1024]
)。
sizeof
returns 4 because your variable is declared as a pointer, as opposed to a C array (char data[1024]
).
要得到你需要使用大小 CGBitmapContextGetHeight
和 CGBitmapContextGetWidth
。
To get the size you need to use CGBitmapContextGetHeight
and CGBitmapContextGetWidth
.