Re: malloc



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.
.



Relevant Pages

  • Thank You -- Thomas J. Gritzan
    ... Thomas -- Your suggestion to malloc() out a block of memory was the ... Below are some details of my memory issues ... ... As a work around solution I guessed a ram disk would solve the ... persistence will frustrate the off topic police and give them a target ...
    (comp.lang.c)
  • Re: Simple question about headers and malloc!
    ... Therefore I am making all of its declarations ... memory (using malloc) and then exit back to main. ... allocation, I get data strored from the second allocation... ...
    (microsoft.public.vc.language)
  • Re: ten thousand small processes
    ... Stack needs to be executable for the current signal trampoline ... the use of malloc() that is causing your primary ... if there is any heap memory in use at all, no matter what you do, ... either directly, as a 4M page mapping (not used for user processes, ...
    (freebsd-performance)
  • Re: Help with Enter and Leave Instructions
    ... >>> for Memory Accesses, ... > The only standard way to do it is via malloc. ... Uh, SBRK/BRK is a standard, documented system call. ... > I really don't understand the objection to using C libraries. ...
    (alt.lang.asm)
  • Re: virtual memory leak? (was: Re: strange problem.....)
    ... and after some time I break this connection. ... executable in heap analyser and still there are no traces of memory ... The debugger is exceedingly programmable, too, ... I'm not a particular fan of malloc and free, ...
    (comp.os.vms)