I'm developing a multi-threaded application in C. I'm currently playing with 40 threads and each uses an array of around 2Mb.
I'm currently allocating this array dynamically, so I do:
char *data = malloc(2097152 * sizeof(char));
These threads are serving requests, so this array is constantly allocated and free'd, each time a new request comes in.
All is working fine, but I'm using valgrind's massif tool and it shows me that I have at times an 80Mb heap. So I'm kind of wondering, will I have heap fragmentation problems? I also allocate smaller chunks of memory on other places of my code.
Also, would I benefit from having an static array? I'm looking of ways to improve my performance and I wonder if this would help. However, I'm afraid of doing that and ending up with a stack overflow. 80Mb in the stack seems too large...
Any advice? I really don't know what size of heap/stack is too big.