I am trying to write a 2d game engine in C (no c++). What are some good libraries that have generic data types I may need - for example queues, trees, maps, lists, and so on?
-
http://stackoverflow.com/questions/305611/container-class-library-for-c/306461#306461 – Nick Van Brunt Mar 16 '09 at 16:25
5 Answers
Take a look at GLib - it has trees, hashmaps, linked lists and queues.

- 15,208
- 2
- 42
- 68

- 34,062
- 14
- 56
- 86
-
According to Wikipedia - yes, cross-platform, although platforms are not listed. – qrdl Mar 16 '09 at 09:22
-
this is a good idea. but glib has a lot of other things I don't need. Is there a slim version of glib thats only the data types. – kthakore Mar 16 '09 at 09:48
-
If it is static lib, only relevant object files will be linked with your binary. Anyway I guess you can roll your own version to include only object files you need. – qrdl Mar 16 '09 at 10:00
-
Fifted, if that's a word. glib for Win32 is a small handful of DLL:s, for the main components ("core", GObject, GIO, GModule, GThread). Total size is around 1.8 MB. – unwind Mar 16 '09 at 14:13
-
In my experience, building glib as a dynamic library on OS X so I can distribute it in my app was a pain -- especially finding all dependencies and getting them to compile. So while glib is theoretically cross-platform, it is a lot of work to get it working on other platforms. – Jakob Egger Jul 26 '13 at 09:30
If you don't want to use a heavy weight library like GLib to use data structures, consider my lightweight version dstruct, it is heavily based on the code Zed Shaw produced in Learn C the Hard Way. It currently features:
- Dynamic array
- Doubly Linked List
- Hashmaps
- Binary Search Tree

- 13,612
- 19
- 65
- 86
You could try any one of the libraries mentioned in #awesome-c list
The cool thing about most of the libraries listed here is that most of them are still actively maintained, so you will not be inheriting a dead library if you decide to use them professionally.
Another #awesome-c list you can use is here

- 39,374
- 15
- 132
- 179
If you are on a mac you will have all of the basic data structures available to you in the core foundations framework.

- 15,244
- 11
- 66
- 92
-
-
1Core Foundation can also be used on Windows, and I guess also on Linux... – Macmade Dec 02 '11 at 01:18
Not sure if this answer is what you're after, but a useful read on the subject is Sedgewick's "Algorithms in C"
HTH

- 3,481
- 2
- 22
- 30