C++ questions - memory allocation speed and using an instance of a class
-
Hi I have two questions on C++: 1. If my application continuously allocate and relase memory (each allocation is around 40Kb, and there may be around 40 allocations and deallocations on each iteration), will the application run faster if I were to write a memory manager class that, instead of freeing the allocated memory, it stores it in e.g. a linked list and reuse it when the app requests for memory? 2. If using a memory manager class will be faster, how can I share an instance of this class among all the classes that needs it? I think it will be more efficient to just create one memory manager instance and share it among all the classes, instead of creating one instance of the memory manager for each class that needs it. Thanks!
-
Hi I have two questions on C++: 1. If my application continuously allocate and relase memory (each allocation is around 40Kb, and there may be around 40 allocations and deallocations on each iteration), will the application run faster if I were to write a memory manager class that, instead of freeing the allocated memory, it stores it in e.g. a linked list and reuse it when the app requests for memory? 2. If using a memory manager class will be faster, how can I share an instance of this class among all the classes that needs it? I think it will be more efficient to just create one memory manager instance and share it among all the classes, instead of creating one instance of the memory manager for each class that needs it. Thanks!
Indrawati wrote: will the application run faster if I were to write a memory manager class This is a great post! In Win32 this would only be true if you think you can improve upon the systems memory manager.
By default, the Process heap performs coalescing operations. (Coalescing is the act of combining adjacent free blocks to build a larger block.) Coalescing costs additional cycles but reduces internal fragmentation of heap blocks.
From: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dngenlib/html/heap3.asp[^]
"No matter where you go, there your are." - Buckaroo Banzai
-pete