Re: realloc, copy and VM
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Mon, 27 Jun 2005 22:05:52 GMT
Michael Wojcik wrote:
>
.... snip ...
>
> Take the typical case: the implementation uses a linear virtual
> address space for all allocated objects, and the contents of C object
> pointers are addresses as used by the virtual memory manager. If an
> object occupies the page at address n*pagesize, and you attempt to
> extend it with realloc, then:
>
> - There may be no page mapped at address (n+1)*pagesize, and the
> implementation could request that the VMM map a new page at that
> address. Aside from performing its internal housekeeping, the
> realloc is done; no copying needs to take place.
>
> - There may be a page mapped at address (n+1)*pagesize. If it's part
> of some other object, then obviously the implementation cannot steal
> that address for the object being resized, because pointers into the
> other object will refer to that portion of the virtual address space.
> The realloc'd object will have to be moved.
There are a lot of possibilities. My nmalloc for DJGPP, available
on my site, mallocs into a linear virtual memory map and trys to
handle all the various possibilities of adjacent free space. The
objective is to avoid memory copies, which it can do when expanding
into free space above. It also checks for free space below, which
may avoid having to assign a new larger junk (and possibly
failing). At any rate it is a simple model, yet has many possible
cases. Available at:
<http://cbfalconer.home.att.download/nmalloc.zip>
--
"I'm a war president. I make decisions here in the Oval Office
in foreign policy matters with war on my mind." - GWB 2004-2-8
"If I knew then what I know today, I would still have invaded
Iraq. It was the right decision" - G.W. Bush, 2004-08-02
"This notion that the United States is getting ready to attack
Iran is simply ridiculous. And having said that, all options
are on the table." - George W. Bush, Brussels, 2005-02-22
.
- References:
- realloc, copy and VM
- From: Jean-Claude Arbaut
- Re: realloc, copy and VM
- From: Michael Wojcik
- realloc, copy and VM
- Prev by Date: fscanf problem
- Next by Date: Re: Implementing my own memcpy
- Previous by thread: Re: realloc, copy and VM
- Next by thread: A biiiig break ?
- Index(es):
Relevant Pages
|