Ideal memory space?
My program calls alot of New to create dynamic memory array, so I'm doing some memory management by only calling New once and create a big page, and then allocate space from this page to new dynamic memory array. If the page runs out of space, I will create another page. So there's a linked list of pages.
My question is what is the suitable size for this page? I read from some source code and the guy set it as 4096. Is this the ideal size? Is it related to our PC cache?
It depends on how much your program allocates. You can set your heap size limits in the linker.
/HEAP: 0x10000, 0x1000
sets 64K(0x10000) of default heap and 4K(0x1000) of reserved heap. The defaults depend on what compiler and API you are using. Essentially, you could check this value by causing a heap overflow and counting the bytes you have allocated on it.
you mean i should allocate the page size to the size of the heap?
What is a reasonable page size directly depends on the application. Say on a average run your program uses 1024 kB of memory. On runs worst then that it uses say an extra couple kBs. So I'd probably set my inital pool to 1024kB and then allocate additional memory in 1kB blocks.
No, that would be using the whole heap which would be very bad, 99% chance you'll have an overflow. Use whatever portion you see fit for the size of heap you are using. If you're open for suggestions, I'd say using 5% of the heap per page, thus leaving plenty of room for other allocations and for other pages.
i'm using g++ in linux, how do I check how much heap space I have? I'm sorry to ask questions that may sound stupid... =)
Or is there any website that teaches us about managing the memory of our application in c++?