G
Guest
hi
i try to malloc 2G size mem . so i wirte code like that.
it failt in freebsd 5.3 and win2k
what's bug in my code ? how can i change it ?
thank all
benjiam
///////////////////////////////////////////////
#include <iostream>
using namespace std;
#include <cstdlib>
const int len = 2000;
int main()
{
char* p1[len];
static int size = int (1<<20);
cout << size << endl;
for (int i =0 ; i < len ;i++)
{
p1 = new char [size];
cout << size << endl;
char *tp = p1;
for ( int x =0 ; x< (size-1); x++)
{
//cout << x << endl;
*(tp+x) = char( (x%26)+ 48);
}
*(tp+size-1) =0;
cout << "p [" << i << "]ok" << endl;
}
for (int i =0 ; i < len ;i++)
{
delete [] p1;
}
return 0;
}
////////////////////////////////////////////
i try to malloc 2G size mem . so i wirte code like that.
it failt in freebsd 5.3 and win2k
what's bug in my code ? how can i change it ?
thank all
benjiam
///////////////////////////////////////////////
#include <iostream>
using namespace std;
#include <cstdlib>
const int len = 2000;
int main()
{
char* p1[len];
static int size = int (1<<20);
cout << size << endl;
for (int i =0 ; i < len ;i++)
{
p1 = new char [size];
cout << size << endl;
char *tp = p1;
for ( int x =0 ; x< (size-1); x++)
{
//cout << x << endl;
*(tp+x) = char( (x%26)+ 48);
}
*(tp+size-1) =0;
cout << "p [" << i << "]ok" << endl;
}
for (int i =0 ; i < len ;i++)
{
delete [] p1;
}
return 0;
}
////////////////////////////////////////////