[openbeos] Re: Performance question - BList vs STL list

  • From: Zenja Solaja <solaja@xxxxxxxxx>
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Sun, 23 Oct 2005 21:14:26 +1000

Thanks, Axel, you nailed my problem very quickly. It was indeed the *(int
**) a which did the trick. I did try with bdb, but was getting the address
of the pointer, and I didn't click into taking a pointer to pointer, even
though I did read the BeBook quote. My mistake (too many hours behind
keyboard this weekend). Also, thank you Marcus for your feedback. During my
haste to to make a quick prototype of my problem, I mistyped d and b, the
real code doesn't have this beginners bug (he he). And yes, the prototype
shuold have used SupportKit, not Storage, another bug in the quick prototype
(which doesn't exist in the real code).

Thanks everyone for your support, I'm back on track. I didn't want to
pollute this list with bug hunting, but the STL version worked first time,
while with BList, I stumbled on pointer to pointer issue, and since they
both used the same sort function, I (incorrectly) assumed that the BList
version didn't work. It just uses another indirection which the STL doesn't
use.

Thanks again.







On 10/23/05, Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> wrote:
>
> Zenja Solaja <solaja@xxxxxxxxx> wrote:
> > Well, I've stumbled onto a bug in BList (SortItems). Examine the
> > following
> > code:
> [...]
> > #include <StorageKit.h> // BList
>
> How about:
> #include <List.h>
> ??
> BList is even part of the Support Kit, not the Storage Kit. Including
> the whole kit for just one class is super-lazy-coder-style :-)
>
> > int int_sort(const void *a, const void *b)
> > {
> > int *c = (int *) a;
> > int *d = (int *) d;
>
> *d = d???
> Also, you are sorting pointers here, not the data they are pointing to.
> Quoting from the BeBook:
> "The arguments passed to the comparison function are declared to be
> void*; however, they should be regarded as pointers to the items in the
> listin
> other words, as pointers to pointers."
>
> IOW it must be:
> int *c = *(int**) a;
> int *d = *(int**) b;
>
> > b_list.AddItem(&sample_data[i]);
>
> Here you are inserting pointers...
>
> > It seems that the BList SortItems() function is b0rken (Zeta R1.1).
> > I've
> > spent all afternoon chasing this bug, and always puzzled why the
> > sorting
> > function never sorted when using BList. I've switched the algorithm
> > to STL,
> > and it works. For the life of me, I cannot see anything wrong at my
> > end.
> >
> > Anyone got any ideas?
>
> Yes, just start adding printfs to your code, or even use BDB and you
> would have found this bug in a few seconds.
>
> Bye,
> Axel.
> 
>
>

Other related posts: