Handmade Hero » Forums » Code » Any good C data structure libraries?
94 posts
#16038 Any good C data structure libraries?
8 months ago Edited by Jason on Aug. 19, 2018, 2:28 p.m. Reason: Initial post

I'm trying to implement my own dynamic memory allocator and in the process of doing so I would like to utilize a linked list structure. Since I don't feel like trying to implement one myself at the moment I tried using STL's linked list just as a current solution. I've had numerous issues trying to get it working so I was wondering if anyone has used and can vouch for any C style libraries for things liked linked lists, arrays, etc?
Mārtiņš Možeiko
1916 posts / 1 project
#16043 Any good C data structure libraries?
8 months ago

If you need just linked list, I would suggest to implement it yourself. Depending on functionality you need it can be very small amount of code - 10/20 lines or so.

As for ready-to-use C code for data structures:
  • here's OpenBSD queue.h and tree.h that implements various queues (singly/doubly linked lists/arrays) and tree structures
  • klib good implementation for various data structures
  • TommyDS with various stuff
  • libldfs if you need lock-free data structures
  • stb.h - also has some data structures

You can also take a look at some implementations of memory allocators to see what they use:
  • tlsf - implements linked list within its data structure, not as external wrapper
  • Hoard
  • nedmalloc
  • ltalloc - C++ not C, but does not use STL

30 posts
#16044 Any good C data structure libraries?
8 months ago


Compared with implementing a whole dynamic memory allocator, implementing a linked list structure will be a breeze, a simple one can be implemented in a few minutes, or maybe a few hours if you're an absolute beginner. Additionally, it is one more opportunity to practice programming to train yourself.
94 posts
#16049 Any good C data structure libraries?
8 months ago

Thanks mmozeiko! And ya I'm sure its not too hard to implement one. I just wanted a quick way to grab something that works reasonably well already while I try and focus on my initial problem. Though I might end up implementing one still we'll see. Thanks again!