From: Matti Aarnio <matti.aarnio@zmailer.org>
To: Lyle Coder <x_coder@hotmail.com>
Cc: David Schwartz <davids@webmaster.com>,
RAJESH BALAN <atmproj@yahoo.com>,
linux-kernel@vger.kernel.org
Subject: Re: malloc(1/0) ??
Date: Tue, 7 Nov 2000 10:46:34 +0200 [thread overview]
Message-ID: <20001107104634.G13151@mea-ext.zmailer.org> (raw)
In-Reply-To: <NCBBLIEPOCNJOAEKBEAKEEAJLMAA.davids@webmaster.com> <OE28zGnClQwSaY2lsLR00001672@hotmail.com>
In-Reply-To: <OE28zGnClQwSaY2lsLR00001672@hotmail.com>; from x_coder@hotmail.com on Tue, Nov 07, 2000 at 12:09:09AM -0800
On Tue, Nov 07, 2000 at 12:09:09AM -0800, Lyle Coder wrote:
> When a program does a malloc... the glibc gets atleast on page (brk)
> [actually, glibs determins of it needs to brk more memory from the kernel...
> because it maintains it;s own pool].. so if you malloc 4 byts, you can copy
> to that pointer more than 4 bytes (upto a page size, ex 4K)... hope that
> answers one of your questions... as far as why malloc(0) works... I dunno
Maybe following extract from glibc's malloc/malloc.c beginning
comments can help you there:
Minimum overhead per allocated chunk: 4 or 8 bytes
Each malloced chunk has a hidden overhead of 4 bytes holding size
and status information.
Minimum allocated size: 4-byte ptrs: 16 bytes (including 4 overhead)
8-byte ptrs: 24/32 bytes (including, 4/8 overhead)
When a chunk is freed, 12 (for 4byte ptrs) or 20 (for 8 byte
ptrs but 4 byte size) or 24 (for 8/8) additional bytes are
needed; 4 (8) for a trailing size field
and 8 (16) bytes for free list pointers. Thus, the minimum
allocatable size is 16/24/32 bytes.
Even a request for zero bytes (i.e., malloc(0)) returns a
pointer to something of the minimum allocatable size.
Maximum allocated size: 4-byte size_t: 2^31 - 8 bytes
8-byte size_t: 2^63 - 16 bytes
Other systems (malloc libraries) may have different strategies on this
allocation management issue, thus allocating anything smaller than the
needed size is bound to get user burned. malloc(0) is insane thing
(IMO), but at least glibc supports it for some reason. Likely just due
to padding and minimum size issues.
> Best Wishes,
> Lyle
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
next prev parent reply other threads:[~2000-11-07 8:46 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-11-07 3:59 RAJESH BALAN
2000-11-07 7:54 ` David Schwartz
2000-11-07 7:59 ` Andrej Hosna
2000-11-07 8:50 ` David Schwartz
2000-11-07 8:09 ` Lyle Coder
2000-11-07 8:46 ` Matti Aarnio [this message]
2000-11-08 0:29 ` Rogier Wolff
2000-11-08 0:36 ` David Schwartz
2000-11-08 0:54 ` Igmar Palsenberg
2000-11-08 0:50 ` Igmar Palsenberg
2000-11-08 22:11 ` H. Peter Anvin
2000-11-08 22:11 ` Rasmus Andersen
2000-11-09 16:03 ` Igmar Palsenberg
2000-11-08 0:41 ` Igmar Palsenberg
2000-11-07 23:58 ` Tim Waugh
2000-11-08 12:38 ` Igmar Palsenberg
2000-11-07 6:45 Dan Kegel
2000-11-07 7:13 ` J. Dow
2000-11-07 7:52 ` David Schwartz
2000-11-08 0:47 ` Igmar Palsenberg
2000-11-07 9:26 malloc (1/0) ?? David Feuer
2000-11-07 16:12 malloc(1/0) ?? Jesse Pollard
2000-11-07 16:38 ` lost
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20001107104634.G13151@mea-ext.zmailer.org \
--to=matti.aarnio@zmailer.org \
--cc=atmproj@yahoo.com \
--cc=davids@webmaster.com \
--cc=linux-kernel@vger.kernel.org \
--cc=x_coder@hotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®