hosseinyounesi -- Do you think you could possibly design your application in terms of objects? In other words, can you please put together an OO design, where you separate object data from object actions.
You are allocating way too much more than you need.
Also, think carefully about the following... what is the value of 'i' at this point in the code?
void * ProcessThread(void * arg)
unsigned long size=0;