Nice to cook this old chestnut again :-)<br><br>Over the years I've gone to great lengths to share tiny memory resources around big projects in deterministic ways. I'm happy to whiteboard at least 3 I invented that are no doubt buried in books of patterns at our next meeting. As memory has become more ubiquitous the pendulum swings the other way and the early use of C++/STL yields huge gains in productivity. Then we may end up spending more time removing the hidden news and deletes down the track.<br>
<br>You can't un-invent these things and I don't subscribe to malloc or new being
bad. Memory allocation and re-allocation are just a nice sharp tools to be used where appropriate.<br><br><a href="http://en.wikipedia.org/wiki/Standard_Template_Library">http://en.wikipedia.org/wiki/Standard_Template_Library</a> is a nice short read.<br>
<br>Richard<br><br><div class="gmail_quote">On Tue, Jul 2, 2013 at 10:54 AM, Charles Manning <span dir="ltr"><<a href="mailto:cdhmanning@gmail.com" target="_blank">cdhmanning@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
As a general principle, I share your disdain of malloc and cronies in<br>
embedded.<br>
<br>
These functions are not at all predictable in their performance and<br>
reliability. With time, vast amounts of malloc/free can cause memory<br>
fragmentation which can, in turn, cause all sorts of "interesting"<br>
behaviours. This is particularly true of the simplistic memory allocators<br>
used in many embedded systems.<br>
<br>
IMHO, well not so humble opinion, it is safe to use malloc etc to allocate<br>
storage which is then managed by a code body as a "pool" or resources for<br>
that code body. This does not cause memory fragmentation and reduces the<br>
number of malloc calls by a buge amount.<br>
<br>
For example, consider some code to handle a network protocol. Buffers could be<br>
created and released on the fly with malloc()/free(), or you could allocate a<br>
pool of buffers and then get then from the buffer or release them back to the<br>
buffer when done.<br>
<br>
<br>
<br>
<br>
On Tuesday 02 July 2013 10:38:46 Mark Atherton wrote:<br>
> <<a href="http://www.embedded.com/design/programming-languages-and-tools/4416457/EMB" target="_blank">http://www.embedded.com/design/programming-languages-and-tools/4416457/EMB</a><br>
>-tm-6-15-13-Dynamic-memory-and-heap-contiguity><a href="http://www.embedded.com/desig" target="_blank">http://www.embedded.com/desig</a><br>
>n/programming-languages-and-tools/4416457/EMB-tm-6-15-13-Dynamic-memory-and-<br>
>heap-contiguity<br>
><br>
><br>
> a while ago, someone at the group looked at me sideways when I<br>
> expressed my disdain about the use of heaps, malloc(), free() etc. in<br>
> an embedded environment.<br>
><br>
> this article covers some of the issues, along with some new ideas.<br>
><br>
> -Mark<br>
><br>
><br>
><br>
> _______________________________________________<br>
> Chchrobotics mailing list <a href="mailto:Chchrobotics@lists.linuxnut.co.nz">Chchrobotics@lists.linuxnut.co.nz</a><br>
> <a href="http://lists.ourshack.com/mailman/listinfo/chchrobotics" target="_blank">http://lists.ourshack.com/mailman/listinfo/chchrobotics</a><br>
> Mail Archives: <a href="http://lists.ourshack.com/pipermail/chchrobotics/" target="_blank">http://lists.ourshack.com/pipermail/chchrobotics/</a><br>
> Web site: <a href="http://kiwibots.org" target="_blank">http://kiwibots.org</a><br>
> Meetings 3rd Monday each month at Tait Radio Communications, 175 Roydvale<br>
> Ave, 6.30pm<br>
><br>
> When replying, please edit your Subject line to reflect new content.<br>
<br>
<br>
<br>
_______________________________________________<br>
Chchrobotics mailing list <a href="mailto:Chchrobotics@lists.linuxnut.co.nz">Chchrobotics@lists.linuxnut.co.nz</a><br>
<a href="http://lists.ourshack.com/mailman/listinfo/chchrobotics" target="_blank">http://lists.ourshack.com/mailman/listinfo/chchrobotics</a><br>
Mail Archives: <a href="http://lists.ourshack.com/pipermail/chchrobotics/" target="_blank">http://lists.ourshack.com/pipermail/chchrobotics/</a><br>
Web site: <a href="http://kiwibots.org" target="_blank">http://kiwibots.org</a><br>
Meetings 3rd Monday each month at Tait Radio Communications, 175 Roydvale Ave, 6.30pm<br>
<br>
When replying, please edit your Subject line to reflect new content.<br>
</blockquote></div><br>