Re: malloc
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Wed, 06 Dec 2006 16:03:16 +0000
milinddeore@xxxxxxxxx said:
santosh wrote:
<snip>
long *b = malloc(1000 * sizeof *b);
long *b1 = b, *b2 = b+250, *b3 = b2+500;
Here, b1, b2 and b3 point to logically seperate blocks of memory, but
since you've partitioned them from a single call to malloc(), they can
all be regarded as contiguous with each other, in the proper order, _as
long as_ you don't reallocate or move any of the blocks.
$$ Good mathematics, but of no use. What if brk/sbrk gives new pages,
as the old page is over.
That's an implementation detail, which makes no difference. Welcome to the
"as if" rule. The implementation is required to behave ***as if*** the
space for the thousand long ints is contiguous, if it is provided at all
(malloc can fail) - even if that space isn't in fact contiguous!
For your information pages are just the
virtual mapping and not guaranteed that they will come contiguous
memory manner.
For your information, the way your implementation works does not affect the
C language; rather, the reverse is true.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
.
- References:
- malloc
- From: ramu
- Re: malloc
- From: santosh
- Re: malloc
- From: ramu
- Re: malloc
- From: santosh
- Re: malloc
- From: milinddeore
- malloc
- Prev by Date: Re: trim function dumping core
- Next by Date: Re: C running strong
- Previous by thread: Re: malloc
- Next by thread: Re: malloc
- Index(es):
Relevant Pages
|
|