sorry! i had changed it to c

G

Guest

sorry! i am not prepense
i write it in c , and comp it under win2k and freebsd5.3

in freebsd
p [ 294 ] ok
1048576
Killed


///////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
const int len = 2000;
int main()
{
char* p1[len];
int i =0;
int x =0;
static int size = 1<<20;
printf( "%d \n", size);
for ( i =0 ; i < len ;i++)
{
p1 = (char*) malloc (size);
printf( "%d \n", size );
char *tp = p1;
for ( x =0 ; x< (size-1); x++)
{
//cout << x << endl;
*(tp+x) = (char)( (x%26)+ 48);

}
*(tp+size-1) =0;
printf( "p [ %d ] ok\n" , i);
}

for ( i =0 ; i < len ;i++)
{
free(p1);
}
return 0;
}



//////////////////////////////////////////

Martin Ambuhl said:
hi
i try to malloc 2G size mem . so i wirte code like that.

You have no guarantee that you can do so. You need to check in a
newsgroup, mailing list, or tech support for your implementation.
it failt in freebsd 5.3 and win2k
what's bug in my code ? how can i change it ?

We really can't help, partially because you posted to comp.lang.c, where
we use C, and your code is not C. comp.lang.c++ is a different newsgroup
for a different language.

Examples of C++isms are:
#include <iostream> This is not a C header.
using namespace std; This is a compilation error.
#include <cstdlib> This is not a C header.
cout << size << endl;
'cout' and 'endl' are undeclared identifiers, and '<<' is a
left-shift operator that probably don't do what you want.
p1 = new char [size];

'new' is an undeclared identifier, and the above is a compilation error.

There are more instances, but I don't care to be tiresome.

 
J

Jack Klein

sorry! i am not prepense
i write it in c , and comp it under win2k and freebsd5.3

in freebsd
p [ 294 ] ok
1048576
Killed

The point is that no matter what language you write it in, the
limitations on how much memory your program can have are determined by
the system, not by the C language, or any other language.

If you want to know whether it is possible to allocate more memory
under Windows, ask in a Windows group like
For the same information
about Free BSD, ask in a BSD group or mailing list.

This is not a limitation of the C language, so the language can't tell
you how to overcome it, if indeed you can at all. Maybe you can't.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top