objective-c中数组的大小限制? [英] size limit on arrays in objective-c?
问题描述
我在目标C中的结构中声明一个数组,如下所示
I'm declaring an array within a struct in objective C as follows
struct myStruct {
int array[size];
};
和另一个
and another one
struct myStruct2 {
double array[size][size];
};
我用一个EXC_BAD_ACCESS代码= 1错误将我的头撞在墙上一段时间然后开始玩我的尺寸。结果是1022很好(1023个元素),但是1023个(1024个元素)并且最多可以解决错误。
为什么?有没有解决的办法? 2 ^ 10
对我不利,这不是巧合。
我真的喜欢至少去2 ^ 14左右。
其他奇怪的东西。在xcode中,当我将鼠标悬停在我的变量size上时,即使已经定义了它,也会显示1457743029,
I banged my head against the wall for a while with an EXC_BAD_ACCESS code=1 error then started playing with my size. Turns out 1022 is fine (1023 elements) but 1023 (1024 elements) and up kicks out the error.
Why? Is there a way around this? It can't be a coincidence that 2^10
is crapping out on me.
I'd really like to go up to about 2^14 at least.
Something else that is strange. In xcode when I hover over my variable "size" it shows 1457743029 even though it is defined,
const int size = 1022;
什么是吗?
编辑:我已经从声明中更新了我的代码,例如
What is that?
edit: I have updated my code from declarations like
myStruct instanceOfStruct;
to
to
struct myStruct *instanceOfStruct = malloc(sizeof(struct myStruct) * size);
memset(instanceOfStruct,0,sizeof(struct myStruct) * size);
但是,我不确定我的大小是否真的应该是大小还是1.我已经包括在内结构中的数组大小 - 我在这里需要占用内存量吗?
However, I am unsure whether my "size" should really be "size" or 1. I've already included array size in the struct - am I squaring the amount of memory I need here?
推荐答案
c#仅限于可用内存量。
Xcode不是c#,你的问题不是c#它是Apple平台的限制。
显然你的是在IOS上更受限制。
如果你想你需要有大型数组,那么尝试不同的方法和算法。
c# is only limited to the amount of memory available.
Xcode is not c#, and your problem is not c# it is the limits of the Apple platform.
Obviously your are more limited on IOS.
If you think you need to have large arrays, then try a different approach and algorithm.
这篇关于objective-c中数组的大小限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!