How to reduce memory problems on high multithreading programs of Windows Mobile
Author : Ester Artieda
From TechnologicalWiki
[edit] Introduction
One of the main problems we have to face when we program on mobile devices is memory limitations. If we don't take care of reserve and free memory while we need it, probably it will appear some memory leaks and disalignments. But some times, althougt we are sure we have allocate memory and free it after use, that memory problems still stay there. In that moment we have to suspect of high multithreading.
[edit] Solution
When you develop programs in Visual Studio, the default thread stack is 1MB of virtual memory which is much more than usual Windows CE programs need to allocate their data. This isn't a very big problem when our process has one or two threads, but when we have a hight multithreading process, our program will early be out of memory.
The best option to avoid this problem is to reduce the thread stack as much as possible, to 64kB (Platform Builder or Windows Mobile Adaptation Kit default thread stack ), and allocate longer stacks only if necessary. To do this, we only have to set a couple of params when we call a CreateThread, dwCreationFlags will be STACK_SIZE_PARAM_IS_A_RESERVATION and dwStackSize will be the size of the stack rounded up to the next 64kB boundary.
On the next photo we can see how to change the default thread stack size:
To get this screen we have to go to Project/properties/linker/system/StackReserveSize and change the default value to 64kB (65536 bytes) and our thread stack size will be finally reduced like our out of memory problems.
[edit] References
http://blogs.msdn.com/kitlfirst/archive/2006/01/31/520197.aspx


