[MPlayer-dev-eng] [RFC] libnut demuxer API

Rich Felker dalias at aerifal.cx
Fri Sep 9 02:44:10 CEST 2005


On Fri, Sep 09, 2005 at 12:24:37AM +0200, Aurelien Jacobs wrote:
> On Thu, 8 Sep 2005 11:32:14 +0200
> Reimar Döffinger <Reimar.Doeffinger at stud.uni-karlsruhe.de> wrote:
> 
> > Hi,
> > On Wed, Sep 07, 2005 at 11:44:39PM +0200, Aurelien Jacobs wrote:
> > > On Wed, 7 Sep 2005 08:45:59 +0300
> > > Oded Shimon <ods15 at ods15.dyndns.org> wrote:
> > > > ahem, yes, malloc :)
> > > > even if you run out of ram, in linux, malloc STILL doesn't fail :P
> > > 
> > > That's plain wrong !!
> > [...]
> > > aurel at homer:~/x$ gcc -Wall -o x x.c
> > > aurel at homer:~/x$ ./x 100000000
> > > 0x2aaaaae02010
> > > aurel at homer:~/x$ ./x 1000000000
> > > (nil)
> > 
> > You have been testing whether an application can malloc any amout of
> > RAM, which of course is not the case.
> 
> No ! I was really checking if malloc fails when you have no more
> free RAM. If I had more than 1GB free ram, `./x 1000000000` wouldn't
> have failed.
> 
> But if you want a better example, here it is:
> 
> aurel at homer:~/x$ free
>              total       used       free     shared    buffers     cached
> Mem:        511040     459992      51048          0      19320     196168
> -/+ buffers/cache:     244504     266536
> Swap:            0          0          0
> aurel at homer:~/x$ cat x.c
> #include <stdlib.h>
> #include <stdio.h>
> #include <string.h>
> 
> int
> main (int argc, char **argv)
> {
>   int s = atoi (argv[1]);
>   while (1)
>     {
>       char *p = malloc (s);
>       printf ("%p\n", p);
>       if (!p)
>         break;
>       memset (p, 0x66, s);
>     }
>   return 0;
> }
> aurel at homer:~/x$ gcc -Wall -o x x.c
> aurel at homer:~/x$ ./x 50000000
> 0x2aaaaae02010
> 0x2aaaaddb3010
> 0x2aaab0d63010
> 0x2aaab3d13010
> 0x2aaab6cc3010
> (nil)
> 
> Here the memset is needed so that the kernel really alloc the memory.
> Without it, no memory would be allocated, and so there would always
> be enough free ram, malloc wouldn't fail, and you would have an
> almost infinite loop.

This is exactly our point. Except that you won't have an infinite
loop, because you'll eventually exhaust the virtual address space of
your process (most likely 1gb or 2gb).

Rich




More information about the MPlayer-dev-eng mailing list