473,378 Members | 1,330 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

malloc() and limitations

I am using malloc to allocation memory for a group of structures. I am
not using a whole lot of memory.
But my program can run without a problem on a machine with 2GB RAM, but
with a machine less than 1GB memory, it fails to allocate memory.

What are the reasons the system cannot allocate memory? How can I fix
this problem?
( when the program starts, I am only using about 40MB memory which is
not a whole lot)

Please help me if you have any ideas

Aug 21 '06 #1
9 5878

questions? wrote:
I am using malloc to allocation memory for a group of structures. I am
not using a whole lot of memory.
But my program can run without a problem on a machine with 2GB RAM, but
with a machine less than 1GB memory, it fails to allocate memory.

What are the reasons the system cannot allocate memory? How can I fix
this problem?
( when the program starts, I am only using about 40MB memory which is
not a whole lot)

Please help me if you have any ideas
you would not be able to allocate memory more then your physical memory
space. possibly the other programs are occupying the rest of the
memory. check out the available free memory using the 'free' command.
- Partha

Aug 21 '06 #2
"questions?" <un************@hotmail.comwrites:
I am using malloc to allocation memory for a group of structures. I am
not using a whole lot of memory. But my program can run without a
problem on a machine with 2GB RAM, but with a machine less than 1GB
memory, it fails to allocate memory.

What are the reasons the system cannot allocate memory? How can I fix
this problem? ( when the program starts, I am only using about 40MB
memory which is not a whole lot)
The amount of memory that your program is allowed to allocate depends
on the operating system. It's very likely that the limit is going to
be far less than the total amount of memory on the system.

The details are implementation-specific. You might try asking in a
newsgroup that's specific to your system. <OT>If you're on a
Unix-like system, look into "limit" and/or "ulimit"; on other systems,
I haven't a clue.</OT>

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 21 '06 #3
use reference point...
regards
<a href=www.gamestotal.com>free</a>
<a href=http://unificationwars.xeepo.com/>online</a>
<a href=http://unificationwars.0catch.com/>online games</a>

Aug 21 '06 #4
use reference point...
regards
<a href=www.gamestotal.com>free</a>
<a href=http://unificationwars.xeepo.com/>online</a>
<a href=http://unificationwars.0catch.com/>online games</a>

Aug 21 '06 #5
pg********@gmail.com writes:
questions? wrote:
>I am using malloc to allocation memory for a group of structures. I am
not using a whole lot of memory.
But my program can run without a problem on a machine with 2GB RAM, but
with a machine less than 1GB memory, it fails to allocate memory.

What are the reasons the system cannot allocate memory? How can I fix
this problem?
( when the program starts, I am only using about 40MB memory which is
not a whole lot)

Please help me if you have any ideas

you would not be able to allocate memory more then your physical memory
space. possibly the other programs are occupying the rest of the
memory. check out the available free memory using the 'free' command.
Not all systems have a "free" command. (In fact, I don't know of any
that do.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 21 '06 #6
questions? wrote:
I am using malloc to allocation memory for a group of structures. I am
not using a whole lot of memory.
But my program can run without a problem on a machine with 2GB RAM, but
with a machine less than 1GB memory, it fails to allocate memory.

What are the reasons the system cannot allocate memory? How can I fix
this problem?
( when the program starts, I am only using about 40MB memory which is
not a whole lot)

Please help me if you have any ideas
My guess is that there is an error in your code.
Perhaps you've miscalculated and did something like
the following:

int sizes[] = {10, 20, 30};
....
ptr = malloc (sizes[4]); /* using garbage value, UB, etc */

Or maybe you did something like this
int length;
....
ptr = malloc (length); /* length uninitialised */
Or you may have even done this
int length = 0;
....
ptr = malloc (length); /* implementation defined,
can return NULL */
Whichever it is, I seriously doubt that any small
program that manipulates a group of structures
can legitimately exhaust memory on a 1G ram
implementation. If you are dealing with such large
amounts of data you are either:
a) reading it from disk and therefore you know how
large it is on disk (is it really supposed to be
a gig?) and should not be surprised when you run
out of memory.
b) you are generating the data yourself, which should
take a tremendous amount of time for non-trivial
algorithms to fill up a gig.

So, please post the smallest compilable code that
causes this problem and perhaps we can spot the
problem.

If you are generating the data from an algorithm,
a short description of the algorithm would be nice
too.

goose,

Aug 21 '06 #7
"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
"questions?" <un************@hotmail.comwrites:
>I am using malloc to allocation memory for a group of structures. I
am
not using a whole lot of memory. But my program can run without a
problem on a machine with 2GB RAM, but with a machine less than 1GB
memory, it fails to allocate memory.

What are the reasons the system cannot allocate memory? How can I fix
this problem? ( when the program starts, I am only using about 40MB
memory which is not a whole lot)

The amount of memory that your program is allowed to allocate depends
on the operating system. It's very likely that the limit is going to
be far less than the total amount of memory on the system.
OTOH, many implementations allow you to allocate far _more_ than the
amount of physical memory. My system has a paltry 512MB of RAM yet user
processes can allocate just shy of 2GB _each_ -- though the system gets
rather slow if you actually try to _use_ that much.

S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking

--
Posted via a free Usenet account from http://www.teranews.com

Aug 21 '06 #8
>What are the reasons the system cannot allocate memory? How can I fix
>this problem?
( when the program starts, I am only using about 40MB memory which is
not a whole lot)

Please help me if you have any ideas

you would not be able to allocate memory more then your physical memory
space.
There are a lot of virtual-memory systems which allow this (assuming
you're not counting swap/page space as "physical memory"). You may
have to override administrative defaults. You may or may not pay
a huge performance penalty which can still be better than the even
worse penalty of not being able to run it at all.

Gordon L. Burditt
Aug 21 '06 #9
go***********@burditt.org (Gordon Burditt) writes:
>>What are the reasons the system cannot allocate memory? How can I fix
this problem?
( when the program starts, I am only using about 40MB memory which is
not a whole lot)

Please help me if you have any ideas
The above was posted by "questions?" <un************@hotmail.com>.
>>you would not be able to allocate memory more then your physical memory
space.
The above was posted by pg********@gmail.com.
There are a lot of virtual-memory systems which allow this (assuming
you're not counting swap/page space as "physical memory"). You may
have to override administrative defaults. You may or may not pay
a huge performance penalty which can still be better than the even
worse penalty of not being able to run it at all.
The above was posted by Gordon Burditt, who continues to insist on
deleting attribution lines in his followups. This is, as always,
extraordinarily rude.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 21 '06 #10

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

Similar topics

231
by: Brian Blais | last post by:
Hello, I saw on a couple of recent posts people saying that casting the return value of malloc is bad, like: d=(double *) malloc(50*sizeof(double)); why is this bad? I had always thought...
6
by: Maja | last post by:
Greetings, /var/adm/wtmp files were getting out of hand and I wanted to filter the file rather than zeroing it out. I found some code that would only keep the last x days but it required...
19
by: Jerry | last post by:
I am wondering what is the maximum size of memory that malloc() could handle. Is there any limitation on that? Where am I supposed to get this kind of information? Thank you everybody.
11
by: subramanian | last post by:
Suppose int size = INT_MAX / 8; char a; are declared to use the feature of variable lenght array(VLA) in C99. With appropriate #includes, when this code is run, segmentation fault occurs in Red...
25
by: Why Tea | last post by:
Thanks to those who have answered my original question. I thought I understood the answer and set out to write some code to prove my understanding. The code was written without any error checking....
47
by: Raman | last post by:
Hi All, As per my understanding, malloc and calloc differs in the way they allocate memory( malloc give a contigous block, But calloc may give Non-contigous block as well). Now consider this...
96
by: pavan | last post by:
Is this code correct char *str = (char *)malloc(10 * sizeof(char)); char = ... char = ... .... .... ... char = '\0';
17
by: Christopher Benson-Manica | last post by:
Some recent posts got me thinking about how one might have dealt with simplistic malloc() implementations which might return NULL for a 64K request but might accept two 32K requests or four 16K...
9
by: anon856525 | last post by:
Hi I recently downloaded Turbo C v2.01 from the borland web site where its being given out for free. Has anyone else tried this? Ive been using it for some months now and hav'nt noted any...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.