A 10Mbyte stack is not reasonable on a small computer like a Rasberry Pi is.
Typical stack frames on the call stack should be a few kilobytes (especially for recent software, which have many dozens functions of call depth, e.g. when using a toolkit like Qt or Gtk).
So I would suggest using the heap in your case.
BTW, once you malloc
-ed a pointer, accessing it (on stack or on heap) is nearly equivalent (there is the cache, but if you access it often enough it will stay in L1 cache). And a typical malloc
(or free
) takes some dozens of microseconds. So for a thousand of such data, heap is not a big deal.
Of course, you'll want to be careful to avoid memory leaks (by free
-ing appropriately the malloc
-ed data). Perhaps use valgrind.
You might consider using Boehm's conservative garbage collector, then you'll code GC_MALLOC
and GC_STRDUP
instead of malloc
and strdup
and you won't bother free
-ing data.