View previous topic :: View next topic |
Author |
Message |
xkjyeah n00b
Joined: 10 May 2003 Posts: 72
|
Posted: Wed Oct 29, 2003 1:38 pm Post subject: Dynamic arrays in C? |
|
|
Are there any libraries that can help me realloc and free pointers automatically? I have hand-coded a varstring.c to help me with unknown string lengths. But are there alternatives by other people, not for just char but also pointers? |
|
Back to top |
|
|
() l33t
Joined: 25 Nov 2002 Posts: 610
|
Posted: Wed Oct 29, 2003 2:14 pm Post subject: |
|
|
I don't know if this is of any help, but from what I understand ISO C99 has variable length arrays (VLA's) and GNU C dynamic arrays. Being primarily a C++ programmer myself I have no experience with these. |
|
Back to top |
|
|
Papapishu Tux's lil' helper
Joined: 18 Mar 2003 Posts: 129 Location: ((void*)NULL)
|
Posted: Wed Oct 29, 2003 7:31 pm Post subject: |
|
|
You could use "map" perhaps? _________________ #359074 |
|
Back to top |
|
|
mike4148 l33t
Joined: 09 Sep 2003 Posts: 641
|
Posted: Wed Oct 29, 2003 11:37 pm Post subject: |
|
|
glib does stuff like that. You probably already have it installed, as it's a prerequisite for gtk. If you don't,
Behold:
|
|
Back to top |
|
|
BlueEar Tux's lil' helper
Joined: 06 Oct 2002 Posts: 143 Location: Mountain View, CA
|
Posted: Thu Oct 30, 2003 12:19 am Post subject: GArray |
|
|
To expand a bit on the previous answer. I use GArray and GPtrArray (see API documentation) available in GLib. You can append, insert and remove elements. You can also sort and search such arrays. I find them very useful and convenient to use. |
|
Back to top |
|
|
CheshireCat Guru
Joined: 25 Aug 2002 Posts: 572
|
Posted: Thu Oct 30, 2003 12:51 am Post subject: |
|
|
You could always consider using C++. There's all kinds of fun stuff in the STL for things like this, and it's all template-based so you can use it with whatever type you want. |
|
Back to top |
|
|
|