Dag-Erling Smørgrav said:
No, but I object to the use of strawman arguments, especially
for purposes of self-promotion.
I think you need to go back and read the thread. The point was the
possible inefficiency that can arise from forcing copying of
existing data. I pointed out that some reallocs go to lengths to
avoid it, and offered my package as an example. Since nmalloc is
tied to DJGPP and would require at least some effort to port
elsewhere, it is only an example. That package is under a free
license anyhow.
The effect can be quite dramatic when the object grows enough to
involve disk access for the copy. The following can be used as a test:
#include <stdio.h>
#include <stdlib.h>
/* Show the sequence of pointers from a series
of calls to realloc, with size doubling */
int main(void)
{
size_t sz;
char *p, *tmp;
sz = 1; p = NULL;
while (sz && (tmp = realloc(p, sz))) {
printf("sz = %8ld p = %p\n", (long)sz, (void *)tmp);
sz += sz; p = tmp;
}
return 0;
}
Results, *_ON MY SYSTEM_*
[1] c:\c\junk>gcc -c trealloc.c
[1] c:\c\junk>gcc trealloc.o -o trealloc.exe
[1] c:\c\junk>gcc trealloc.o malloc.o
*** Original malloc system ***
[1] c:\c\junk>timerun .\trealloc
Timer 3 on: 21:40:26
sz = 1 p = 90108
sz = 2 p = 90108
sz = 4 p = 90108
....
sz = 16777216 p = 10949a0
sz = 33554432 p = 20949b0
Timer 3 off: 21:40:27 Elapsed: 0:00:00.49
*** revised nmalloc system ***
[1] c:\c\junk>timerun .\a
Timer 3 on: 21:40:59
sz = 1 p = 90ce8
sz = 2 p = 90ce8
....
sz = 16777216 p = 95c78
sz = 33554432 p = 95c78
Timer 3 off: 21:40:59 Elapsed: 0:00:00.05
Incidentally the above also serves as an example of replacing the
system malloc on some systems. Note that this is not a portable
technique, and you can be seriously bitten.
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <
http://cfaj.freeshell.org/google/>