473,734 Members | 2,788 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to malloc 2G ram? in freebsd, win2k

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[i] = new char [size];
cout << size << endl;
char *tp = p1[i];
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[i];
}
return 0;
}
////////////////////////////////////////////
Nov 14 '05 #1
23 3021
ch***********@h otmail.com wrote:
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[i] = 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.
Nov 14 '05 #2
In article <d1**********@n ews.yaako.com>, <ch***********@ hotmail.com> wrote:
: 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 ?

And how are you compiling? It is fairly common for there to be a 2 GB
process size limit unless you specifically compile to use 64 bit
pointers. Yes, in theory with 32 bits you -could- get to 4 GB instead
of 2 GB, but it is not uncommon for half of the memory to be reserved
for system pointers.

Even within the 2 GB limit, it is common for there to be address space
layout issues: it is common for your code not to be placed at address 0
in virtual memory, and it is common for there to be an area reserved
for the stack, and it is common for there to be an area reserved for
the heap, and it is common for there to be one or more areas reserved
for DLLs or equivilent. You may have to give special linking options or
run special post-processors on the executable image in order to move
these reserved areas to give yourself the maximum amount of room.

On Unix systems it is also common for there to be resource limits that
prevent you from using gobs of memory unless you override them or get
the systems administrator to override them. See the 'ulimit' man page
to get yourself started, and the getrlimit() functions. The mechanisms
used by the systems administrator to control the limit would very with
unix version; I do not know the details for freebsd.

--
Entropy is the logarithm of probability -- Boltzmann
Nov 14 '05 #3
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[i] = (char*) malloc (size);
printf( "%d \n", size );
char *tp = p1[i];
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[i]);
}
return 0;
}

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

"Martin Ambuhl" <ma*****@earthl ink.net>
??????:u6****** *******@newsrea d2.news.atl.ear thlink.net...
ch***********@h otmail.com wrote:
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[i] = 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.

Nov 14 '05 #4
ch***********@h otmail.com wrote:
.... snip ... #include <iostream>
using namespace std;


comp.lang.c++ is down the hall to the right.

--
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare

Nov 14 '05 #5
On Tue, 22 Mar 2005 16:35:15 +0800, <ch***********@ hotmail.com> wrote:
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
/////////////////////////////////////////// [...]
p1[i] = (char*) malloc (size);


This causes undefined behaviour when malloc returns NULL. Check the return
value.
Nov 14 '05 #6
ch***********@h otmail.com wrote:
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 ?


I don't know about FreeBSD, but on Windows a process cannot be bigger
than 2G, even if you have more RAM than that. Each process is limitted
to at most 2G. So, if you add the space for your code, libraries, and
existing variables, malloc'ing 2G on a Windows box is guaranteed to fail.

I _think_ Linux gives you 3G, but I could be wrong. I don't know if
these limits persist to AMD-64 or not. However, I would try it on a
64-bit PowerPC -- it should work there.

Jon
----
Learn to program using Linux assembly language
http://www.cafeshops.com/bartlettpublish.8640017
Nov 14 '05 #7
Raymond Martineau wrote:
<ch***********@ hotmail.com> wrote:
.... snip ...
p1[i] = (char*) malloc (size);


This causes undefined behaviour when malloc returns NULL. Check
the return value.


No it doesn't. NULL is a perfectly valid value for a char*.
However the useless cast can conceal errors, and should be avoided.

However, there may be a later problem when using p[i].

--
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare
Nov 14 '05 #8
CBFalconer <cb********@yah oo.com> spoke thus:
No it doesn't. NULL is a perfectly valid value for a char*.
However the useless cast can conceal errors, and should be avoided. However, there may be a later problem when using p[i].


I think this is what he was actually referring to, although his
quoting could have been better.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #9

#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[i] = (char*) malloc (size);
printf( "%d \n", size );
char *tp = p1[i];
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[i]);
}
return 0;
}

Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2314
by: pembed2003 | last post by:
Hi, If I have the folllowing: char* p = malloc(5); memset(p,-1,5); *p = 0; printf("%d\n",strlen(p)); free(p); It will print 0. Is there a way to retrive the initial size of memory
2
1432
by: dsptechie | last post by:
I wanted to how exactly malloc() function works. I came to know that malloc() allocates memory only in powers of 2. i.e if asked for say 17 bytes , in the process, it allocates 32 bytes and returns 17 bytes so 15 bytes are wasted... Is this true...If anybody knows the algorithm details of malloc() plase share the same. Is this one of the reason why malloc() is not generally preferred in embedded systems..?
40
540
by: ramu | last post by:
Hi, what happens when i run the below code? main() { int *p; while(1) p= (int *)malloc(1000); } Do i get segmentation fault?
37
3199
by: ravi.cs.2001 | last post by:
Hi all, I m relatively new to C. I have few queries related to malloc(): #1. When we perform malloc(), the memory allocated dynamically comes from the heap area of the process in concern. Well, we then say that the heap has shrinked. my query is: Is it that the heap physically does not shrink but the perticular nodes are marked 'ALLOCATED' and for subsequent calls to malloc() the memory manager remembers them and does not reference...
34
13395
by: niranjan.singh | last post by:
This is regarding to test an SDK memory stuff. In what situation malloc gets fail. any comment/reply pls.... regards
6
3371
by: itsolution | last post by:
Hi folks, Could you shed some light on this issue? my program is running on Freebsd as a daemon. When user sends a request, it forks itself and lets its child process handles the request. And its main role is just to read a big xml file and save each object into its embedded DB(such as gdbm).
11
1680
by: pushpakulkar | last post by:
Hi all, Many users claim that malloc() and free() provided by the language library results in considerable amount of overhead in terms of calling the same. Can we really eliminate overhead by using used defined functions/user defined memory manager. Is there any significant advantage in providing user defined malloc() and free(). I want to exclude realtime systems or embedded systems which are memory constrained here.
0
1953
by: Akira Kitada | last post by:
Hi Marc-Andre, Thanks for the suggestion. I opened a ticket for this issue: http://bugs.python.org/issue4204 Now I understand the state of the multiprocessing module, but it's too bad to see math, mmap and readline modules, that worked fine before, cannot be built anymore.
0
1813
by: M.-A. Lemburg | last post by:
On 2008-10-25 20:19, Akira Kitada wrote: Thanks. The errors you are getting appear to be related to either some missing header files or a missing symbol definition to enable these - looking at the ticket, you seem to have resolved all this already :-)
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.