Re: realloc but not copy



websnarf@xxxxxxxxx wrote:

.... snip ...

I had a similar issue in implementing the Better String Library.
For reasonably large allocations, the performance is usually going
to be limited by the copy. Now, if your data is anything like
Bstrlib's the problem is that the allocated buffer is usually
larger than the amount of valid data that its holding. But
realloc doesn't know this, and so will copy the entire buffer on
realloc if a data move is required.

That is a problem better handled in the realloc function proper.
nmalloc goes to lengths to avoid any copying during realloc. It
can do this because it maintains quickly accessible knowledge of
the size and availability of adjacent memory chunks.

<http://cbfalconer.home.att.net/download/>

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

.



Relevant Pages

  • Re: realloc but not copy
    ... For reasonably large allocations, ... realloc if a data move is required. ... but then that's one reason why Vstr is designed the way it ... if (tmp = realloc(Yptr, X)) Yptr = tmp; ...
    (comp.lang.c)
  • Re: realloc but not copy
    ... For reasonably large allocations, ... realloc if a data move is required. ... the size and availability of adjacent memory chunks. ... then that's one reason why Vstr is designed the way it is (it doesn't need ...
    (comp.lang.c)
  • Re: realloc return value
    ... If realloc is successful, will the return pointer be the same as p ... same size *could* relocate it. ... future allocations. ...
    (comp.lang.c)
  • Re: passing pointers [C]
    ... > Since you only call realloc, there is no way for old allocations not ... Your problem stems from the fact that you are using ... rid of the double pointer business (it seemed a bit too clever for its ...
    (alt.comp.lang.learn.c-cpp)
  • Re: How to take in a string of any size?
    ... Richard Pennington wrote: ... snip ... ... > A good implementation of realloc() will probably return the same ... block of memory even when the original block is constrained by ...
    (comp.lang.c)