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.
------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users