----- Original Message ----- From: "Wouter van Ooijen" To: "Microcontroller discussion list - Public." Sent: Wednesday, October 14, 2009 4:28 PM Subject: Re: [PIC] Dynamically Allocating Memory in C > Bob Ammerman wrote: >> Careful use of dynamically allocated memory can make sense in an embedded >> application. As examples, I will document the way dynamic memory is used >> in >> three large embedded systems I have developed (one in assembler, one in C >> and one in C++) that all use carefully managed dynamic memory allocation. >> It >> is interesting to note that several techniques, as outlined below, can be >> used to avoid the twin bugaboos of fragmentation and memory exhaustion. >> Admittedly all of these systems have much more memory than a PIC. > > Wouter van Ooijen replied: > Note that the three examples you cite do not use 'general' > malloc/free-style dynamic memory. Did you use a compiler-provided > (C-style) malloc at all? I understand that you certainly did not use free. > > In all three cases you took explicit action to avoid fragmentation. > Except for the double-pointer example approach one could argue that (in > the other two) you don't use dynamic memory at all: you might as well > have used one or more statically allocated arrays and hand out (and take > back) array entries. Absolutely. Although in the C++ case the application 'thinks' it is using normal 'new' and 'delete'. I just replaced the 'new handler', which is actually supported by the C++ standard, IIRC. -- Bob Ammerman RAm Systems -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist