C++ Builder

Moderators: Lundin
Number of threads: 518
Number of posts: 1158

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
how to avoid 'stack overflow' error in c++ builder Posted by skolli06 on 25 Jun 2009 at 2:16 PM

Hi,

I have a problem when initializing a large array of size as below:
int main()
{
float a[6][56000];
getch();
return 0;
}

I need such size of array for my project but c++ builder is throwing me error-
Loaded 'C:\WINNT\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcr80d.dll', Symbols loaded.
'ims_project.exe': Loaded 'C:\WINNT\system32\msvcrt.dll', No symbols loaded.
First-chance exception at 0x00411437 in ims_project.exe: 0xC00000FD: Stack overflow.
Unhandled exception at 0x00411437 in ims_project.exe: 0xC00000FD: Stack overflow.
The program '[3912] ims_project.exe: Native' has exited with code 0 (0x0).

please help me with this problem.
Report
Re: how to avoid 'stack overflow' error in c++ builder Posted by AsmGuru62 on 26 Jun 2009 at 5:35 AM
float* a[6];
int i;

// Allocate array dynamically
for (i=0; i<6; i++) a[i] = new float [56000];

... do your work with the array ...
float value = a [4] [34872];

// Release memory
for (i=0; i<6; i++) delete [] a[i];
Report
Re: how to avoid 'stack overflow' error in c++ builder Posted by bilderbikkel on 10 Aug 2009 at 4:27 AM
You can
- create the arrays dynamically (as shown in other reply)
- use a std::vector (which does the dynamic allocation and deallocation for you)

In C++, prefer a std::vector over an array (see http://richelbilderbeek.nl/CppVector.htm for references).

#include <vector>
std::vector<std::vector<float> > a;


See ya, Bilderbikkel




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.