CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588

    C++ Memory Management: Why does declaring an array cause my program to crash?

    Q: Why does declaring an array cause my program to crash?

    Code:
    double x[500000];
    A: Because such a large piece of memory exceeds the stack size (a stack overflow). You need to allocate the memory on the heap instead:

    Code:
    double* x = new double[500000];
    Don't forget to delete the memory (with 'delete[]') after you are finished with it to avoid memory leaks.


    FAQ contributed by: [Kevin Hall]


    Last edited by Andreas Masur; July 23rd, 2005 at 01:46 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured