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

  • From: "Axel Dörfler" <axeld@xxxxxxxxxxxxxxxx>
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Sun, 23 Oct 2005 12:06:14 +0200 CEST

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: