Parker
Parker

Reputation: 59

Maximum array size in objective C on iPhone?

I have a VERY large array (96,000 elements of type GLfloat). It was previously 24,000 elements, until I made a couple of changes. Now I'm getting a crash. I haven't done much to debug it yet, but when I noticed how ridiculously large one of my arrays was getting I thought it might be worth looking into. So, my only question is whether 96,000 elements (or 384,000 bytes) is too much for a single array?

Upvotes: 1

Views: 2406

Answers (3)

justin
justin

Reputation: 104708

That should be fine on the heap, but you should avoid allocations of that size on the stack. So malloc/free or new[]/delete[] is what you should use to create and destroy an array of that size.

If the device has low memory, you can expect requests for large amounts of memory to occasionally return NULL. There are applications (such as photo/image processing) which request allocations at tens of megabytes -- many times greater than your 384 KiB allocation.

Upvotes: 2

tia
tia

Reputation: 9708

I don't think it's too big. Some image resources would take up that much or more contiguous space without problem. For example, a 400x400px image would take about 160,000*4 = 640,000 bytes of memory. I think the problem is somewhere else.

Upvotes: 0

Lily Ballard
Lily Ballard

Reputation: 185811

There is no upper bound on the size of an array, save the amount of available RAM on the device.

Upvotes: 1

Related Questions