kdelibs/kdecore
Dirk Mueller
kde-optimize@mail.kde.org
Thu, 20 Mar 2003 18:49:43 +0100
On Don, 20 M=E4r 2003, Eray Ozkural wrote:
> Implement the optimization mentioned in revision 1.84 and 1.85 without br=
eaking KDE big time (finally)
Sorry, your implementation is just as much broken as before. Would you=20
please post a patch before you commit to kdelibs?=20
> + // new/delete and malloc/free are not compatible
> + d =3D (Z*) malloc(sizeof(Z)*sz); // allocate 2 elts
> + memset( (void*) d, 0, sizeof(Z)*sz );
use calloc.=20
> + // open table has amortized O(1) access time
> + // when N elements appended consecutively -- exa
> + int newsize =3D max(2*sz, index+1);
> + // copy into new larger memory block using realloc
> + d =3D (Z*) realloc(d, sizeof(Z)*newsize);
> + memset( (void*) &d[sz], 0, sizeof(Z)*(newsize-sz) );
> + sz =3D newsize;
Once again, you cannot set the size to the number of elements you allocated=
=20
on spare. This breaks the semantics of an array.=20
Also, I didn't see any justification about how much improvement this patch=
=20
brings. All I can see is that it might use a lot more memory right now.=20
--=20
Dirk