lkml.org 
[lkml]   [2000]   [Mar]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Avoiding OOM on overcommit...?
On Sat, 25 Mar 2000, Sandy Harris wrote:

> James Sutherland wrote:
>
> > >> >BUT "when I use up the resources given to me" - If the resources
> > >> >weren't available, why did the system give them to me?
> > >>
> > >> It didn't.
> > >
> > >If he did a [mc]alloc to ALLOCate the the memory and got a non-null
> > >return, it certainly said it did.
> >
> > No - malloc() doesn't allocate MEMORY, it allocates ADDRESS SPACE to
> > put memory in later. This may not be what you wanted, but that's what
> > it does.
>
> Both 'man malloc' and 'info malloc' on my SuSE 6.3 system say it
> "allocates memory". At the very least, these pages need some text in
> the BUGS section explaining what they actually do.
>
> Also, you describe what malloc() currently does on Linux, but it is by
> no means clear that that's what it should do.
>
> Checking the C standard at:
>
> http://anubis.dkuug.dk/JTC1/SC22/WG14/www/docs/n843.htm
>
> I find:
>
> 7.20.3 Memory management functions
>
> ... The pointer returned if the allocation succeeds ...
> may be ... used to
> access such an object or an array of such objects in the
> space allocated (until the space is explicitly freed or
> reallocated).
>
> The calloc function allocates space for an array of
> nmemb objects, ...
>
> The malloc function allocates space for an object ...
>
> Notice that the standard makes no distinction between calloc() and
> malloc(). Both "allocate space".

The "memory management" functions are just to a standard way to
manage an heap. "memory management" has a completely different
meaning than the kernel "memory management" subsystem.

> Earlier in this thread, though, someone suggested replacing malloc()
> with calloc() to ensure that space actually gets allocated. That should
> not be necessary.

malloc() is the same of calloc() on Linux. The difference is there
because C is not a UNIX-only thing. You can compile C programs under DOS.

Zeroing memory should be done explicitly. I don't believe it pays anything,
but that's another thread.

.TM.
--
____/ ____/ /
/ / / Marco Colombo
___/ ___ / / Technical Manager
/ / / ESI s.r.l.
_____/ _____/ _/ Colombo@ESI.it


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:57    [W:0.185 / U:4.200 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site