Re: heap
"George" wrote:
Another example. Suppose you need to perform some heap
intensive time critical computation. So, you make private
heap and use it for the computation, which only
allocates,
but not releases. When the computation is done, you just
destroy the whole heap. So, you can save deallocation
time
during the computation.
Destroy heap is faster than free memory?
Yes, destroying a heap once can be faster than many small
operations on it. Just think about what deallocation must
do:
1. Find a memory chunk to free by provided address. Usually
heap stores addresses of memory chunks on highly optimized
internal container, but still it takes time to find things
there.
2. Lock access to prevent collisions from other threads (if
a heap is thread safe).
3. Mark the memory chunk as free and/or move it to the other
container that stored available chunks. Exact action is
depends on heap implementation.
4. Unlock access.
You can avoid all these steps if your code never frees
memory. If your code allocates/deallocated many times, then
it can be quite a burden on a heap manager.
What is the relationship between using memory mapped file
to share memory
and share heap? Could you provide more information please?
You can't share heap, that the point. All you can do is to
share some memory area. It's up to you what to do with this
memory.
Alex