Re: Unusual memory allocation problem

Richard B. Johnson (root@chaos.analogic.com)
Tue, 15 Sep 1998 08:29:53 -0400 (EDT)


On Mon, 14 Sep 1998, Chetan Kumar wrote:

> Hi
> Take a look at this piece of code, I compiled this with gcc ver
> 2.7.2.1 on linux box 2.0.30, with i486, 8M ram and 16M swap, to my surpise
> I did not get any error, the code succeeded allocating 400*2M mem !!!!
>
> On the other hand on a sloaries I could promplty get error Could not find
> free space.
>
> Any this buggy !?!
> with thanks
>

This seems correct to me. Malloc() and friends take a size_t variable
for the number of bytes to allocate and you did not exceed that. Note
that this is a virtual machine, malloc() returns a pointer to a 'promise'.
Only one page was actually allocated so far. Actual memory allocation
occurs as you access beyond the end of each page of virtual memory. This
allows programs that allocate large amounts of memory, but never actually
get to use it all, to function perfectly well.

Cheers,
Dick Johnson
***** FILE SYSTEM WAS MODIFIED *****
Penguin : Linux version 2.1.118 on an i586 machine (66.15 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.

-
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/