Re: malloc under linux



santosh <santosh.k83@xxxxxxxxx> writes:
jacob navia wrote:
[...]
This makes any serious usage of malloc completely impossible!

Theoretically, but practically this is not much of a problem for most
programs.

It always return true!

No. It means what it says, i.e., even if malloc returns a non-null pointer,
memory might not actually be allocated. Linux attempts to do so, when the
memory is actually written to.
[...]

jacob's statement isn't an unreasonable inference, though. Given the
description, it's plausible that malloc() will always return a
non-null result (which can be interpreted as "true").

An experiment on my own Linux box shows that it doesn't *quite* work
that way; malloc() does return a null pointer for very large arguments
(above about 2.1 gigabytes on a system with 1 gigabyte of physical
memory).

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <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."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages

  • malloc under linux
    ... Linux follows an optimistic memory allocation strategy. ... This means that when malloc() returns non-NULL there is no guarantee that the memory really is available. ... jacob navia ...
    (comp.lang.c)
  • Re: malloc under linux
    ... Linux follows an optimistic memory allocation strategy. ... This means that when malloc() returns non-NULL there is no guarantee ...
    (comp.lang.c)
  • Re: malloc under linux
    ... Linux follows an optimistic memory allocation strategy. ... This means that when malloc() returns non-NULL there is no guarantee ...
    (comp.lang.c)
  • Re: Memory problem
    ... > I test the memory usage with my System Resources Manager and the top ... > command (I work with Linux but the Mac forums are the only place to go ... There are two levels of memory allocation going on here, ... One level is the malloc level, where you can request things in byte-sized ...
    (comp.sys.mac.programmer.help)
  • Thank You -- Thomas J. Gritzan
    ... Thomas -- Your suggestion to malloc() out a block of memory was the ... Below are some details of my memory issues ... ... As a work around solution I guessed a ram disk would solve the ... persistence will frustrate the off topic police and give them a target ...
    (comp.lang.c)