|
From: Mark S. <ms...@cl...> - 2005-05-20 00:27:04
|
>So here's a question. How does the following variant behave?
...
That version behaves properly, but this modification (walking each
buffer after it's been allocated) does not:
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv)
{
int len =3D 0;
char *data =3D NULL;
int do_copy =3D 1;
for(int i=3D0; i<2000; i++) {
len +=3D 4096;
char *data =3D (char *) malloc(len*sizeof(char));
for (int j=3D0; j<len; j++) {
data[j] =3D j;
}
free(data);
}
return 0;
}
Some nonscientific analysis (i.e. watching "top" while valgrind is
running) indicates that the memory usage is initially stable, then
quickly climbs as the buffer gets larger.=20
--Mark
|