<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Array length changeable during Run - Time</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/16755/array-length-changeable-during-run---time</link><description> Hi everyone 
 
Does someone know how to change the length 
of on array during the run time execution? 
I mean how can I request memory to use 
it for a array? Is there somthing like 
malloc()? 
 
Thanks! </description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Array length changeable during Run - Time</title><link>https://community.arm.com/thread/86790?ContentTypeID=1</link><pubDate>Wed, 26 May 2004 12:08:39 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1a410c64-78a7-43e7-b99d-e8e364a2ac54</guid><dc:creator>Dan Henry</dc:creator><description>&lt;p&gt;&lt;i&gt;&amp;quot;To answer your question directly there is indeed something like malloc(): malloc(), in fact.&amp;quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
And then to answer your question even more directly about runtime changes, after malloc(), you would use realloc() to change size.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.keil.com/support/man/docs/c51/c51_realloc.htm"&gt;http://www.keil.com/support/man/docs/c51/c51_realloc.htm&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array length changeable during Run - Time</title><link>https://community.arm.com/thread/86786?ContentTypeID=1</link><pubDate>Wed, 26 May 2004 11:01:36 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:14e91bf7-2f39-4b78-be95-d9fb8637d8a4</guid><dc:creator>Jon Ward</dc:creator><description>&lt;p&gt;The small model benchmarks for malloc and free may be found at: &lt;a href="http://www.keil.com/benchmks/tm_c51_v7_small.asp"&gt;http://www.keil.com/benchmks/c51_alloc.asp&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
The benchmark results are from the Knuth memory allocation test as described in Fundamental Algorithms, Section 2.5 Dynamic Storage Allocation.  In other words, the results in the benchmark are likely to be close to what you see in your implementation.&lt;br /&gt;
&lt;br /&gt;
Note that the free() function in the Keil libraries merges adjacent free blocks.  This is NOT true of most malloc/free implementations.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Jon&lt;/b&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array length changeable during Run - Time</title><link>https://community.arm.com/thread/42268?ContentTypeID=1</link><pubDate>Wed, 26 May 2004 07:42:40 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f2fda1cb-0162-484e-a978-939699faaacb</guid><dc:creator>John Donaldson</dc:creator><description>&lt;p&gt;&amp;quot;Is there somthing like malloc()?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
To answer your question directly there is indeed something like malloc(): malloc(), in fact.&lt;br /&gt;
&lt;br /&gt;
However, as others have pointed out using malloc() is a bad idea in most 8051 situations. If you need dynamic allocation because your total memory requirements exceed your available memory then declare arrays as local variables within functions and let the overlay manager perform its magic.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array length changeable during Run - Time</title><link>https://community.arm.com/thread/86789?ContentTypeID=1</link><pubDate>Wed, 26 May 2004 07:32:23 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:b754d69a-cbe2-4be3-b51d-6539da8bce58</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;i&gt;&amp;quot;You will probably be better off allocating maximum array size at compile time.&amp;quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Yes.&lt;br /&gt;
&lt;br /&gt;
Think about it: even if you do use malloc (or similar) you will have to define the size of the &amp;quot;pool&amp;quot; from which this allocates its memory - so you will need to know the maximum array size at compile time anyway.&lt;br /&gt;
&lt;br /&gt;
So why waste your time, and the compiler&amp;#39;s, and some CPU run time with dynamic allocation?&lt;br /&gt;
&lt;br /&gt;
Just Don&amp;#39;t Do It!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array length changeable during Run - Time</title><link>https://community.arm.com/thread/42267?ContentTypeID=1</link><pubDate>Wed, 26 May 2004 06:29:54 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:d2bcf2ce-568c-4faa-875d-951b5354fccc</guid><dc:creator>Mik Kleshov</dc:creator><description>&lt;p&gt;You will probably be better off allocating maximum array size at compile time. Dynamic memory allocation in a 8051-based design is generally a bad idea. Just do a search in this forum with keywords like &amp;quot;malloc&amp;quot; or &amp;quot;dynamic&amp;quot; for further discussion.&lt;br /&gt;
&lt;br /&gt;
- mike&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>