RE: [DEV-C++] BUG: Dev-C 4.9.20 consolprogram has only access to 1MB memory.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ho...> - 2002-05-10 02:52:05
|
Your code fixed:
#include <iostream>
//-->Not needed
// #include <stdio.h>
#include <stdlib.h>
//--> You do not use argc, argv[] so why you declare them?
int main(int argc, char *argv[])
{
using namespace std; // --> necessary
const long MEGA_BYTE = 1024*1024;
long nMBSize = 1;
while (nMBSize != 0 ){
cout << "Give MB size: ";
cin >> nMBSize;
//--> Illegal in ANSI C++. The sizes of arrays in the stack must be
constants
//--> char narrBig[nMBSize * MEGA_BYTE];
char *narrBig=new char[nMBSize*MEGA_BYTE];
//--> Useless. sizeof(char) is always 1 byte
//cout << "char size: " << sizeof(char) << " Bytes." << endl;
//-->You can't do that on an array on the free store.
// Here it returns the size of char *
// cout << "Array size: " << sizeof(narrBig)<< " Bytes." << endl;
//See if initializing each element makes a difference
for (unsigned long i = 0; i<nMBSize*MEGA_BYTE;i++){
narrBig[i] = 'A';
}//i
//--> Useless. cout << "Array size: " << sizeof(narrBig) << endl;
//If you store objects in the array remember to use:
delete [] narrBig;
//--> This could be disastrous when applied on a built in array as you
had done
}//while (nMB..
//To have a breake before window closes, use:
system("PAUSE");
return 0;
}
====
How i would do it in your case:
#include <iostream>
#include <cstdlib>
#include <vector>
int main()
{
using namespace std;
const unsigned long MEGA_BYTE = 1024*1024;
long nMBSize;
do
{
cout << "\nGive MB size: ";
cin >> nMBSize;
vector<char> narrBig(nMBSize*MEGA_BYTE);
cout << "Array contents size: " << narrBig.size()<< " Bytes." <<
endl;
for (unsigned long i = 0; i<nMBSize*MEGA_BYTE;i++)
narrBig[i] = 'A';
cout << "Array contents size: " << narrBig.size()<< " Bytes." <<
endl;
// vector is destroyed at the end of its scope, and its contents are
cleared
}while (nMBSize!=0);
//To have a break before window closes, use:
system("PAUSE");
return 0;
}
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf Of staale
> Sent: Friday, May 10, 2002 4:46 AM
> To: jar...@be...; ha...@bl...; Dev-Cpp
> Subject: [DEV-C++] BUG: Dev-C 4.9.20 consolprogram has only
> access to 1MB memory.
>
>
> Se also thread:
> [Dev-C++] not enough memory - how to configure Win2000
> on the mailing list. Test code below
>
> Hi Helmuth,
>
> Turns out this has somthing to do with Dev-C 4.9.20.
>
> This is what I did to verify the problem:
> 1: Tried your file on both w2k (Clean system) or NT4-Sp6. It
> failed on both
> machins.
>
> 2: I installed DEV-C 4.9.20 (downloaded today) on a clean w2k
> machine and
> encountered the same problem when I compiled and ran the code.
>
> 3: Tried to uninstall DEV-C 4.9.20. Uninstal DOES NOT work.
> Delete the fiels
> manualy. Search for dev-c in regedit.exe and then run
> RegClean.exe just
> search for RegClean and you should be well of (Might not nead
> this see pkt
> 5)
>
> 4: Installed DEV-C 4.0 on the w2k machine Compiled and
> tested OK to 31MB.
>
> 5: Installed Dev-c 4.9.20 on top of the 4.0 and It still
> worked nicely..:o)
>
> 6: Installed Dev-C 4.9.20 on NT4-SP6 (Only Winzip appart from
> OS). Added
> shlwapi.dll and wininet.dll to system32 folder. Tried to run
> the code but
> no. Same failure.
>
> 7: Installed Dev-C 4.0 on top of the 4.9.20. This did not
> help. Brobably
> because both installers does not overwrite existing header
> files (?). So you
> should delete the 4.9.x installaation. Install 4.0 and then
> 4.9.x (if you
> nead it. It is a must if you want to use the wxWindows lib,
> if I understand
> right)
>
>
> I'm not a seasoned C developer but would gues there are
> somthing wrong with
> a header file or reference making dev-c 4.9.x compile to
> 16bit code(???)
>
> Best regards
> Staale Flock
>
> ------------------- Code
> Start --------------------------------------------------------
> //////////////////////////////////////////////////////////////
> //////////////
> ///////////////////////////////////////////////////
> // this code fails if you install Dev-C 4.9.20 on a new w2k
> machine and try
> to access
> // more than 1MB memory. (Enter any number higher than 1).
> //////////////////////////////////////////////////////////////
> //////////////
> ///////////////////////////////////////////////////
>
> #include <iostream>
> #include <stdio.h>
> #include <stdlib.h>
>
>
> int main(int argc, char *argv[])
> {
> const long MEGA_BYTE = 1024*1024;
> long nMBSize = 1;
> while (nMBSize != 0 ){
> cout << "Give MB size: ";
> cin >> nMBSize;
> char narrBig[nMBSize * MEGA_BYTE];
> cout << "char size: " << sizeof(char) << " Bytes." << endl;
> cout << "Array size: " << sizeof(narrBig)<< " Bytes." << endl;
> //See if initializing each element makes a difference
> for (unsigned long i = 0; i<nMBSize*MEGA_BYTE;i++){
> narrBig[i] = 'A';
> }//i
> cout << "Array size: " << sizeof(narrBig) << endl;
> //If you store objects in the array remember to use:
> delete []narrBig;
> }//while (nMB..
> //To have a breake before window closes, use:
> system("PAUSE");
> return 0;
> }
>
> ------------------- Code end --------------------------------->
|