23

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).

Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192
Igor Krivokon
  • 10,145
  • 1
  • 37
  • 41
  • 1
    I realize it is a (quite) duplicated question : First line in SO searching tool: http://stackoverflow.com/questions/2540/good-stl-like-library-for-c , and there is quite more, just searching for " [c] glib library" – yves Baumes May 20 '09 at 21:12
  • 3
    Zifre - no, it's not a solution (for me). I've been progrmaming C++ for almost 20 years, so I don't think I need any advice on available C++ libs. Here I was interested what's happening in pure C land. And I'm very satisfied with the answers, thanks everyone! Especially that "C interfaces and implementations" - it looks like a gem. – Igor Krivokon May 21 '09 at 20:57
  • at this point I'am just wondering why the C std comitee never provided a standardisations for a common and widely used library. Glib is quite used AFAIK? C++ commitee bring the STL in the standard for instance ... Well , is it a good question for SO ? :P – yves Baumes May 22 '09 at 01:04

8 Answers8

15

Isn't Glib sufficient for your needs ? :-) developer.gnome.org/glib

Amr Ayman
  • 1,129
  • 1
  • 8
  • 24
yves Baumes
  • 8,836
  • 7
  • 45
  • 74
14

Apache Portable Runtime

http://apr.apache.org/

Includes modules for these areas.

  • Platform Definitions
  • Internal Memory Allocation
  • Atomic Operations
  • Dynamic Object Handling
  • Functions for manipulating the environment
  • Error Codes
  • File Information
  • File I/O Handling Functions
  • Filename Matching Functions
  • Miscellaneous library routines
  • Command Argument Parsing
  • Global Locking Routines
  • Hash Tables
  • General Purpose Library Routines
  • MMAP (Memory Map) Routines
  • Network Routines
  • Poll Routines
  • Memory Pool Functions
  • Portability Routines
  • Process Locking Routines
  • Random Functions
  • Ring Macro Implementations
  • Shared Memory Routines
  • Signal Handling
  • String routines
  • Internal APR support functions
  • Table and Array Functions
  • Condition Variable Routines
  • Thread Mutex Routines
  • Threads and Process Functions
  • Reader/Writer Lock Routines
  • Time Routines
  • User and Group ID Services
luser droog
  • 18,988
  • 3
  • 53
  • 105
Unknown
  • 45,913
  • 27
  • 138
  • 182
14

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
  • 198,648
  • 61
  • 360
  • 533
7

I previously recommended MemSL, but the website and company seem to have gone extinct. I would now suggest glib, it covers much of the same functionality and is widely supported and used throughout the Linux community.

I used MemSL 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
Andrew Hundt
  • 2,551
  • 2
  • 32
  • 64
  • The MemSL link does not work (at the moment, 2012-06-08). This link seems to have the MemSL nowadays: http://www.memorystructures.com/. The download link goes to http://sourceforge.net/projects/memsl2/(with last update 2009-11-12). – FooF Jun 08 '12 at 11:05
  • I updated the link, it should work again. – Andrew Hundt Jun 08 '12 at 13:44
  • looks like MemSL is dead. I updated my reply to make note of that and added a link to glib, which is probably a better alternative anyway since it has wide support. – Andrew Hundt Oct 01 '13 at 22:10
5

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.

Community
  • 1
  • 1
none
  • 5,701
  • 28
  • 32
4

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

Lear
  • 1,893
  • 2
  • 13
  • 9
2

Let me add:

http://libslack.org

(... and add to this: libcx)

2

You may interested in looking at qLibc.

http://en.wikipedia.org/wiki/Qlibc http://www.qdecoder.org/qlibc/

It's a general purpose complete C/C++ library which includes all kinds of containers and general library routines.

Richard
  • 21
  • 1