Click here to Skip to main content
15,036,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm declaring an array within a struct in objective C as follows
Objective-C
struct myStruct {
    int array[size];
};

and another one
Objective-C
struct myStruct2 {
    double array[size][size];
};

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,
Objective-C
const int size = 1022;

What is that?

edit: I have updated my code from declarations like
Objective-C
myStruct instanceOfStruct;

to
Objective-C
struct myStruct *instanceOfStruct = malloc(sizeof(struct myStruct) * size);
memset(instanceOfStruct,0,sizeof(struct myStruct) * size);

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?
Posted
Updated 2-Aug-14 11:39am
v5
Comments
CHill60 2-Aug-14 10:55am
   
Why have you used C# in your title and tags??
Member 10983886 2-Aug-14 17:38pm
   
I was thinking it was short for objective C for some reason.

1 solution

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.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900