Re: Policy on rebooting?
From: Peter Bushell (NOpeter.bushell_at_SPAMsoftware-integrity.com)
Date: 10/07/04
- Next message: Jack: "Failure of 68HC908KX8 Monitor Mode"
- Previous message: Ben: "need help with setting up echotek race++"
- In reply to: Michael N. Moran: "Re: Policy on rebooting?"
- Next in thread: Michael N. Moran: "Re: Policy on rebooting?"
- Reply: Michael N. Moran: "Re: Policy on rebooting?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 7 Oct 2004 14:58:51 +0100
"Michael N. Moran" <mike@mnmoran.org> wrote in message
news:GU99d.179610$Np2.98150@bignews4.bellsouth.net...
> D. Zimmerman wrote:
>>
>> 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.
>
The fixed-size-block allocation scheme is foolproof unless some fool tries
to circumvent its "shortcomings" by doing the kind of thing you describe
above. The solution is to have the right number of right-sized pools
containing the right number of right-sized blocks (as you say below) - but
with *no poaching allowed*. If you can't get the proper-sized block, then
there aren't enough, so back to the drawing board. Stealing a bigger block
from another pool (transparently or not) is not acceptable; it just
re-introduces fragmentation by the back door.
> 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.
>
I agree wth eschewing malloc() and free(). However, if you want to use C++
effectively in an embedded system, you really have to customise new() and
delete() to use a safe, fixed-size-block scheme tailored to your system.
This is painful, but essential. It is very hard to use C++ effectively
without using new() and delete().
> 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.
>
True, but better that than the indeterminacy of fragmentation.
> BTW, allocation is not the issue. If memory is never freed,
> then fragmentation will not happen. Of course, then its not
> *really* dynamic.
>
Also true, and not as daft as it sounds. Using such a "heap" is quite a
convenient way of initially allocating pools, stacks, etc.
-- -- Peter Bushell http://www.software-integrity.com/
- Next message: Jack: "Failure of 68HC908KX8 Monitor Mode"
- Previous message: Ben: "need help with setting up echotek race++"
- In reply to: Michael N. Moran: "Re: Policy on rebooting?"
- Next in thread: Michael N. Moran: "Re: Policy on rebooting?"
- Reply: Michael N. Moran: "Re: Policy on rebooting?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|