Array problem

Hello, I'm having a little problem with my app. I created a MFC app, then I put something like:
 
MYSTRUCT array1[5000];

When I ran the app, it crashed. I thought there had to be a limit to the elements of arrays. Can anyone give me an advice?
Last edited on
variables can go on the stack or on the heap. Stack space is much more limited than heap space.

Variables that are local to functions are placed on the stack. Globals I'm not sure about. And stuff allocated with new is put in the heap.

You can try putting your array on the heap instead of on the stack:

1
2
3
4
5
MYSTRUCT* array1 = new MYSTRUCT[5000];

// use array1 here

delete[] array1;  // then don't forget to delete[] it 


Or you can forego the cleanup by letting std::vector take care of the cleanup for you:

1
2
3
std::vector<MYSTRUCT> array1(5000);

// use array1 here 
Useful information, thank you.
Topic archived. No new replies allowed.