tags:

views:

785

answers:

8

Could you recommend a good general purpose data container library for C (pure C, not C++)? I just need basic structures, like dynamic arrays, hash tables, etc.

(Note: By "good" I mean fast + elegant interface).

+9  A: 

Apache Portable Runtime

http://apr.apache.org/

Unknown
+5  A: 

http://home.gna.org/gdsl/

jbm
+8  A: 

Isn't Glib sufficient for your needs ? :-) Glib link to what it provides

yves Baumes
+5  A: 

You might also want to check out the iMatix SFL, to quote their webpage:

The SFL (Standard Function Library) from iMatix is a portable function library for C/C++ programs. The SFL is the result of many years' development, and is provided as Open Source software for the benefit of the Internet community. The SFL is written in ANSI C and has been ported to MS-DOS, Windows, OS/2, Linux and other UNIX systems (IBM AIX, SunOS, HP/UX, Solaris, NetBSD, FreeBSD, SCO OpenServer,> Digital UNIX) and Digital OpenVMS. It comes with complete sources and documentation in HTML.

The SFL provides about 450 functions that cover these areas:

  • Compression, encryption, and encoding;
  • Datatype conversion and formatting;
  • Dates, times, and calendars;
  • Directory and environment access;
  • User and process groups;
  • Inverted bitmap indices;
  • Symbol tables;
  • Error message files;
  • Configuration files;
  • String manipulation and searching;
  • File access;
  • Internet socket access;
  • Internet programming (MIME, CGI);
  • SMTP (e-mail) access;
  • Server (batch) programming;
  • Program tracing.

The SFL is free software that you may use and distribute for private or commercial purposes according to the SFL License Agreement.

More details about the API itself, see here.

none
+5  A: 

I think Dave Hanson's C Interfaces and Implementations qualifies as both fast and elegant. It includes many different kinds of containers, some string processing, multiprecision arithmetic, exceptions, a couple of different memory managers. Nice stuff.

There's a book, but you don't need to buy it to use the software.

Norman Ramsey
+3  A: 

Sglib "is a generic library for C that was inspired by the Standard Template Library from C++"

Lear
+4  A: 

I recommend MemSL. I used the library when implementing an x86 kernel, and I found it to be general, reliable, and bug free.

From the description: C Overview of the Memory Structures Library (MemSL)

The Memory Structures Library, MemSL for short, is a library of useful routines allowing the efficient use of complex data structures in C. The MemSL contains routines for managing:

  • Multi-Dimensional Dynamically Allocated Arrays
  • Single Linked Lists
  • Double Linked Lists
  • Circular Linked Lists
  • Cut, Copy and Paste with Linked Lists
  • Multiple Positional Pointers to Linked Lists
  • Stacks
  • Queues
  • Dequeues
  • Sets
  • Bags
  • Tables
  • Dictionaries
  • Hash Tables with Separate Chaining
  • Hash Tables with User-Defined Paging
  • Hash Tables with Dynamic Paging
  • Binary Search Trees
  • Threaded Binary Search Trees
  • AVL Balanced Binary Search Trees
  • AVL Balanced Threaded Binary Search Trees
  • Priority Heaps
  • Fully Dynamic Priority Search Queues
doomdayx
+2  A: 

Let me add:

http://libslack.org

(... and add to this: libcx)