On Thu, Oct 8, 2009 at 9:39 PM, Vitaliy wrote: > You might as well declare pointers evil and taboo, since they cause a far > greater amount of damage when the programmer using them doesn't know what > she's doing. > So how will the program know you need this or that size of memory? If the communication protocol allows you to tell the size of the buffer they are going to send to you then you definitely need to validate the size if that was allowed by the system design or not. Otherwise you will see some problems, like the other party will say "give me 2G of RAM". Now if you know the max size (so you can validate it), then you can also allocate that at compile time, can't you? :-) Or if you re talking about a continuously growing buffer that you are keep reallocating while receiving the stream, then you might will face to a memory walking problem where you cannot extend the memory easily because of fragmentation. Hence you are always getting a new place at a higher and higher memory address location till you will reach the highest memory address. Your buffer walks through the memory space and then there will be nowhere to go. At that point all you can do is a garbage collection but for that you need to use double-pointers and of course you need to do double dereferencing all the time. Other option is to well defining at which point can you do the "rubbish" so you can pin-point the memory handlers and re-pinning every time there was that point passed on. That leads to other possible software bugs (forgetting re-pinning) so then you implement pinning-unpinning which makes the whole memory management even more complicated... These are known techniques on a PC or on a Mac or on some largish embedded systems (especially in Java based ones), but not sure if that worth the effort on a PIC? Tamas > > >> The point is that you can run into the same problem ("out of memory") > >> with > >> static memory allocation. It's not a problem inherent to dynamic memory > >> allocation. > > > > However, with static allocation you will be informed by the compiler or > > the > > linker that there is a problem -- and not when the customer is asking for > > help. > > Say you allocate a static buffer to hold data that you receive over UART. > What happens if the buffer is too small to hold the data? Your compiler has > no idea how big your buffer needs to be, or whether it will overflow or > not. > > Vitaliy > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- http://www.mcuhobby.com -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist