Toolbox essentials

| No Comments | No TrackBacks
Well, I was reading '5 more essentials for your programming toolbox' and the first entry has my favourite - unfolded linked lists. It's just that it's broken in at least one way. You should embed the list of 'void *' pointers at the end of the entry using the magic of the zero length array at the end.
struct unrolled_listitem {
    int num_elements;
    struct unrolled_listitem *next;
    void *pointers[0];
}
You get the size of a struct item from (sizeof(struct unrolled_listitem) + num_elements * sizeof(void *)). You need to min/max it to the size of a cache line.
The issue is that if you want to embed this structure in another one, you need to add padding after it to the max of the size of the structure that you are planning on allocating.

No TrackBacks

TrackBack URL: http://www.petesh.com/scgi-bin/MT/mt-tb.cgi/156

Leave a comment

About this Entry

This page contains a single entry by Pete Shanahan published on March 16, 2008 9:58 PM.

It's just been one of those weeks I suppose was the previous entry in this blog.

And another complaint about the N95 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.