I wonder if there is an alternative for the std::vector in C? I found this implementation but it seems to contain some issues with memory reallocation.
Asked
Active
Viewed 6,615 times
13
-
1which part of std::vector is bothering you that you're looking for an alternative implementation? – Peyman Feb 07 '11 at 17:38
-
5@Peyman: maybe he doesn't have a C++ compiler... – Pablo Santa Cruz Feb 07 '11 at 17:40
-
1I am developing some code for the SmartXA2 based microcontroller and there is only a C compiler for it. – ezpresso Feb 07 '11 at 17:43
-
4if this is an embedded system there may also be limits on malloc, memcpy and a limited amount of memory - you may be better off allocating a fixed maximum array at the start – Martin Beckett Feb 07 '11 at 17:58
3 Answers
10
You can give glib and its arrays (GArray
) a try.
glib is actively maintained, cross platform, open source (LGPLv2+), and it doesn't stop on arrays/vectors. You also have hash tables, linked lists, queues and many other data structures.

Cristian Ciupitu
- 20,270
- 7
- 50
- 76

Pablo Santa Cruz
- 176,835
- 32
- 241
- 292
-
2
-
2You are probably right. He didn't mention he was going to use it in an embedded system when I answered the question though... – Pablo Santa Cruz Feb 07 '11 at 18:31
9
While reading C Array vs. C++ Vector, I found an interesting implementation of a simple vector container in C, which also includes push/pop operations. It's worth reading it!

The Guy
- 106
- 2