6

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?

Mihai Limbășan
  • 64,368
  • 4
  • 48
  • 59
kthakore
  • 1,566
  • 3
  • 17
  • 32

5 Answers5

11

Take a look at GLib - it has trees, hashmaps, linked lists and queues.

Wikipedia article.

user694733
  • 15,208
  • 2
  • 42
  • 68
qrdl
  • 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
0

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
chutsu
  • 13,612
  • 19
  • 65
  • 86
0

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

smac89
  • 39,374
  • 15
  • 132
  • 179
0

If you are on a mac you will have all of the basic data structures available to you in the core foundations framework.

Nick Van Brunt
  • 15,244
  • 11
  • 66
  • 92
-2

Not sure if this answer is what you're after, but a useful read on the subject is Sedgewick's "Algorithms in C"

HTH

dcw
  • 3,481
  • 2
  • 22
  • 30