Thanks! But is there any more? I'm not a computer scientist, just an electrical engineer who learnt how to program tutorial-style. I really don't know what heap or stack memory is. And wikipedia isn't very helpful. Do you know of any book that explains this matters?
Thanks! --------------------------------------- Sergio Campamá sergiocamp...@gmail.com On Sep 29, 2011, at 6:25 PM, David Brown wrote: > On 29/09/11 21:00, Sergio Campamá wrote: >> On Thu, Sep 29, 2011 at 3:55 PM, David >> Brown<david.br...@hesbynett.no>wrote: >> >>> On 29/09/11 20:52, Sergio Campamá wrote: >>>> Hello, >>>> >>>> I was under the impression that in C you could not do something >>>> like: >>>> >>>> void func(int size) { int array[size]; //something return; } >>>> >>>> But a friend of mine just proved me wrong, using mspgcc... >>>> Searching around we found this to be VLA (variable length array) >>>> Does this kind of usage fall into dynamic memory? My impression >>>> is that the answer is yes, and therefore it shouldn't be used on >>>> microprocessors, because malloc can cause havoc (as someone told >>>> me some emails ago in this very same group). >>>> >>>> What are your thoughts on VLA? Does it use malloc internally, and >>>> therefore should be avoided? >>>> >>> >>> Variable length arrays are like any other data - they can go in >>> various places. In a case like this, you have defined a non-static >>> local variable - just like any other non-static local variable, it >>> goes on the stack. So as long as you are careful not to overflow >>> your stack, this should be fine - it doesn't suffer from the risks >>> you get with malloc (or, more accurately, the risks you get with >>> free), namely unpredictably long delays, fragmented heaps, and no >>> space errors. >>> >> Thanks David. I have been meaning to understand fully well how >> memory works in terms of stack and ram. Is there any text or >> resource available that could help me understand that? >> > > It's basic C. Anything defined with a static lifetime (global data, > static local data) is statically allocated at fixed memory addresses. > Anything local to a function is either kept in registers (or removed > altogether by the optimiser) or put on the stack. Anything allocated by > malloc (or standard "new" in C++) goes on the heap. > > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure contains a > definitive record of customers, application performance, security > threats, fraudulent activity and more. Splunk takes this data and makes > sense of it. Business sense. IT sense. Common sense. > http://p.sf.net/sfu/splunk-d2dcopy1 > _______________________________________________ > Mspgcc-users mailing list > Mspgcc-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/mspgcc-users ------------------------------------------------------------------------------ All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 _______________________________________________ Mspgcc-users mailing list Mspgcc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mspgcc-users