Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Dynamic arrays in C?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
xkjyeah
n00b
n00b


Joined: 10 May 2003
Posts: 72

PostPosted: Wed Oct 29, 2003 1:38 pm    Post subject: Dynamic arrays in C? Reply with quote

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
View user's profile Send private message
()
l33t
l33t


Joined: 25 Nov 2002
Posts: 610

PostPosted: Wed Oct 29, 2003 2:14 pm    Post subject: Reply with quote

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
View user's profile Send private message
Papapishu
Tux's lil' helper
Tux's lil' helper


Joined: 18 Mar 2003
Posts: 129
Location: ((void*)NULL)

PostPosted: Wed Oct 29, 2003 7:31 pm    Post subject: Reply with quote

You could use "map" perhaps?
_________________
#359074
Back to top
View user's profile Send private message
mike4148
l33t
l33t


Joined: 09 Sep 2003
Posts: 641

PostPosted: Wed Oct 29, 2003 11:37 pm    Post subject: Reply with quote

glib does stuff like that. You probably already have it installed, as it's a prerequisite for gtk. If you don't,
Code:
emerge glib

Behold:
Code:
info glib
Back to top
View user's profile Send private message
BlueEar
Tux's lil' helper
Tux's lil' helper


Joined: 06 Oct 2002
Posts: 143
Location: Mountain View, CA

PostPosted: Thu Oct 30, 2003 12:19 am    Post subject: GArray Reply with quote

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
View user's profile Send private message
CheshireCat
Guru
Guru


Joined: 25 Aug 2002
Posts: 572

PostPosted: Thu Oct 30, 2003 12:51 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum