Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Oct 2003 09:42:28 -0700 (PDT)
From:      Mark Terribile <materribile@yahoo.com>
To:        freebsd-questions@freebsd.org
Cc:        James Jacobsen <james_jacobsen@lycos.co.uk>
Subject:   Re: malloc() behavior (was: Pointer please)
Message-ID:  <20031006164229.55196.qmail@web21104.mail.yahoo.com>
In-Reply-To: <20031006120313.D41CE16A4F1@hub.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help


>>>> It does not matter what freebsd does, C does
>>>> not require that malloc initialize space
>>>> according to Kernighan and Ritchie.
>> ... What's really bad, is that freebsd could
>> potentally change there behavor down the line.
>> Its probably dictated by the way kernel dezined,
>. meaning they may do whats the cheapist.

> There's nothing bad about it.  FreeBSD follows
> the standards.  ...

There's a distinction here which has been mentioned
and perhaps lost.  The kernel does provide programs
with zero'd memory, but unless you are doing system
calls (man section 2) directly you are not seeing
what the kernel does.  You are seeing what the C
language runtime code (malloc(), calloc(), free(),
etc.) does.  They use the system calls, but the
semantics are the semantics that the authors of
the runtime implemented.  And since the runtime is
provided with the compiler (typically gcc) it's
only a function of convenience when the language
definition says it may be.

The kernel's pool of zero'd buffer pages is used to
provide zero'd memory on demand while doing the work
when the CPU may be free.  Sort of like washing the
dishes before you need them.  The kernel C code
does not use the C runtime, except possibly for some
very low-level routines that might be needed to
implement extended precision, do stack frame
management, or other very-low-level stuff.  And
there's precious little needed on newer processors.

                                  Mark Terribile


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031006164229.55196.qmail>