Re: Policy on rebooting?

From: D. Zimmerman (7UPdzimmerman_at_stny.rr.com)
Date: 10/08/04


Date: Fri, 08 Oct 2004 03:07:24 GMT

Michael N. Moran wrote:
> D. Zimmerman wrote:
>
>> Paul Keinanen wrote:
>>
>>> On Wed, 6 Oct 2004 11:16:58 +0200, "mk" <REVERSE_lp.pw@myzskm.REMOVE>
>>> wrote:
>>>
>>>
>>>> Why is dynamic memory allocation bad idea?
>>>
>>>
>>>
>>>
>>> Fragmentation.
>>>
>>
>> This also depends on the operating system being used. Most real time
>> OS's, which are often used for embedded, will only allocate fixed size
>> memory blocks and will reclaim the entire block. This prevents the
>> problem Paul described.
>
>
> This does not *prevent* the problem, it only limits/slows the problem
> if the application has a particular pattern of dynamic memory usage.
>
> Imagine a limited supply of large fixed size blocks. If these blocks
> are allocated and released and then subsequently allocated and
> fragmented to fulfill the needs of another part of the system
> requiring a smaller block size (of which there are no more), then
> eventually such an allocation system will fail as well.
>
> Of course, we're talking about general malloc/free new/delete here,
> not private memory pools, which are pre-allocated for a particular
> part of the system with fixed sized blocks.
>
> What's more is that block memory allocation schemes reduce the
> "memory efficiency" advantages of dynamic memory allocation by
> wasting the unused portion of each allocated block.
>
> BTW, allocation is not the issue. If memory is never freed,
> then fragmentation will not happen. Of course, then its not
> *really* dynamic.
>
Actually, it does prevent the problem. The reason is that
the RTOS won't take (for example) a 256 byte space and
re-allocate it in smaller chunks, then turn around and try
to make a 256 byte allocation out of a 128 byte and two 64
byte blocks. Basically there is a memory pool.

The downside is what you alluded to in that it is not as
memory efficient. For example, a structure that needs 200
bytes will get a 256 byte allocation. Life is not perfect.

Dennis,

-- 
If sending a reply you will need to remove "7UP".


Relevant Pages

  • Re: How to release heap memory that is marked as free
    ... As I said, fragmentation is a very serious problem, and one of the most serious problems ... my allocator was accused of using massive amounts of memory. ... I'm going to have to re-think the memory allocation that I'm ... process's 'working set'. ...
    (microsoft.public.vc.mfc)
  • Re: [PATCH 00/28] Swap over NFS -v16
    ... memory they can consume. ... So we need the extra (skb) ... included in the reserve? ... if the allocation had to dip into emergency reserves, ...
    (Linux-Kernel)
  • Re: CMemoryState & multi-threaded application
    ... released, and interspersed with smaller allocations, *will* cause fragmentation. ... I've sometimes done this by having a thread that wakes up once a minute and traces memory. ... Manager, Process Viewer, etc., since they are largely clueless about storage allocation ...
    (microsoft.public.vc.mfc)
  • Re: Memory leak with CAsyncSocket::Create
    ... read my essay on how storage allocators work. ... Create method is consuming system memory that is not released back to ... The memory consumption is either shown as "Mem Usage" on the Task ... many levels of allocation going ...
    (microsoft.public.vc.mfc)
  • Re: OT: C++ overloading operators
    ... dynamic allocation, no matter how many "clever tricks" are used... ... though there's enough memory in the system, ... all these "flexible data types" map into CPU command ... The computing environment is completely ...
    (comp.dsp)