Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tlug: gcc question



"Stephen J. Turnbull" wrote:
> 
>     Fredric> Malloc use sbrk(2) (or brk(2)) to ask the kernel for more
>     Fredric> memory when it needs it (there are btw probably also
>     Fredric> other ways than sbrk(2) to do this).
> 
> The man page doesn't say so, but there may be a POSIX way to get
> memory (brk and sbrk are not POSIX).
There is mmap(2) (POSIX). I was told by somebody that I consider
very good on Linux kernel code that modern malloc implementation
probably use mmap(2) and leaves unaccessible pages to fence in some
areas, for example the internal data structures.
The only part that bugs me is that I can not see that it would be
possible to used both sbrk(2) and mmap(2) in the same program.
Maybe malloc does not use mmap(2) or maybe mmap(2) can be used
in a "safe" way together with sbrk(2).

> 
>     Fredric> Consider the following c program:
> 
> It works for me too, although I don't know how offhand to determine
> whether malloc is requesting integral multiples of the pagesize from
> sbrk.
> 
> However, I do not get all the way to the end of the segment; in my
> case, the stdout buffer doesn't get flushed before the SEGV occurs.
> What version of glibc do you have?  (Mine is glibc 2.1.2, Debian
> package revision 10.)
Well, you caught me with my pants down here ;-). I cheated and
copied the first part from stdout redirected to a file and the
last was part copy-paste from output to an xterm. My glibc is by 
the way also 2.1.2.

/Fredric
--------------------------------------------------------------------
Next Nomikai Meeting: February 18 (Fri) 19:00 Tengu TokyoEkiMae
Next Technical Meeting:  March 11 (Sat) 13:00 Temple University Japan
* Topic: TBD
--------------------------------------------------------------------
more info: http://www.tlug.gr.jp        Sponsor: Global Online Japan


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links