malloc(), virtual memory

Chris Torek chris at umcp-cs.UUCP
Sat Sep 7 03:42:12 AEST 1985


> From: jon at cit-vax (Jonathan P. Leech)

>> From: Chris Torek
>> ... Since as distributed 4.2 has a per-process VM limit of 6M, you
>> cannot allocate more than 4M with malloc.

> I don't understand how this works. Suppose I allocate two blocks,
> one 4M (2^22 bytes) and one 2M (2^21). These are both powers of
> two, and I get 6M total.  Or does malloc round it up by a factor
> of two if you are unlucky enough to request a power of two . . . .

Sorry, I was not specific enough.  You can allocate one 4M chunk
and one 2M chunk; you cannot allocate one 6M chunk.

The size you hand to malloc has (in our C library at any rate) 4
added to it, then the result is brought up to the nearest power of
two.  So if you give it ((1 << 22) - 4) you will get a 4M chunk;
one more byte and malloc will require an 8M chunk.  (If you compile
malloc with range checking the overhead grows to 12 bytes.)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at maryland



More information about the Comp.lang.c mailing list