468,512 Members | 1,396 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

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 5575

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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

231 posts views Thread by Brian Blais | last post: by
6 posts views Thread by Maja | last post: by
19 posts views Thread by Jerry | last post: by
11 posts views Thread by subramanian | last post: by
25 posts views Thread by Why Tea | last post: by
47 posts views Thread by Raman | last post: by
96 posts views Thread by pavan | last post: by
17 posts views Thread by Christopher Benson-Manica | last post: by
9 posts views Thread by anon856525 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.