[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-optimize
Subject:    Re: kdelibs/kdecore
From:       Stefan Heimers <stefan () heimers ! ch>
Date:       2003-03-19 22:07:43
[Download RAW message or body]

Am Wednesday 19 March 2003 22:55 schrieb Tim Jansen:
> On Wednesday 19 March 2003 21:12, Eray Ozkural wrote:
> > -        Z *newdata = new Z[index + 1];
> > +        // open table has amortized O(1) access time
> > +        // when N elements appended -- exa
> > +        Z *newdata = new Z[max(2 * sz, index+1)];
>
> How can the rest of the code know that the array is bigger than
> index+1 if you don't modify it as well?

He might have forgotten to set sz to the new size, or just didn't post 
everything. Does the following make more sense? (IMHO still a waste of 
memory)

else if (index >= sz) {
...
+        Z *newdata = new Z[max(sz = 2 * sz, index+1)];


sz might not be unique, so you need to put it in the data structure, eg. 
newdata->sz.
_______________________________________________
Kde-optimize mailing list
Kde-optimize@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-optimize
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic