Olin Lathrop escreveu: > Quintin Beukes wrote: > = >> I was hoping for some advice/corrections on dynamically allocating >> memory. >> = > > Some compilers come with heap and dynamic memory management routines. Use > them if they are there, or roll your own if you want or need to, but don't > just go grabbing memory you think isn't in use. > > Why do you need to dynamically allocate memory anyway? This is rather > unusual in a small embedded system, and likely indicates big system think= ing > on a small system. I've only done on the fly real persistant memory > allocation on a PIC once that I can remember, and in that case the memory > being allocated was actually out on a ENC28J60 ethernet MAC/PHY with the = PIC > keeping track of the allocated regions. I have sometimes needed a tempor= ary > buffer and the like inside a single routine on a 18F. In those cases I h= ave > so far just temporarily appended the buffer to the data stack. > > What problem are you really trying to solve? > > = >> 4. I _assume_ the compiler will use ... >> = > > This sounds like really bad design. Don't assume, know. But even if you > did know for sure, that only applies to this rev of this compiler. Guess= ing > where unused memory is without using the proper mechanisms to allocate it= is > heading for trouble. For example, how do you know the data stack isn't > allowed to grow into the left over memory? > > = >> Then chosen as follows: Any addresses above A9, and to accommodate >> future changes, use any above 200, and carefully monitor my compiles? >> = > > Yuck! That is really bad design. Indeed, your heap must be declared as a normal variable (big array of char) so the compiler and linker locate it properly. If you just use an address range you *think* is not in use then next time you link it, it may be on top of some other variable. Then your allocator "cuts" chunks of it and gives to your application (return the chunk address). See the sink I posted in my previous reply, it is exactly what you need, and very well tested. If you need help to get started just send me a message. Best regards, Isaac __________________________________________________ Fa=E7a liga=E7=F5es para outros computadores com o novo Yahoo! Messenger = http://br.beta.messenger.yahoo.com/ = -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist