<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/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/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Memory allocation limitations on the nRF52840?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/37349/memory-allocation-limitations-on-the-nrf52840</link><description>Hi, 
 I am using the nRF52840, which has 256KB of RAM, (i.e. loads and load of RAM.) 
 I would like to allocate a buffer of 45KB. 
 I have tried using malloc (from the stdlib.h, in SEGGER Embedded Studio for ARM 3.40) to allocate some memory buffers,</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 14 Mar 2021 08:51:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/37349/memory-allocation-limitations-on-the-nrf52840" /><item><title>RE: Memory allocation limitations on the nRF52840?</title><link>https://devzone.nordicsemi.com/thread/299603?ContentTypeID=1</link><pubDate>Sun, 14 Mar 2021 08:51:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d4e08613-4b16-4ba8-93c6-4c565c62811f</guid><dc:creator>ray</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have a same problem.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I would like to allocate a buffer of 128KB.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;it is not work well, eventhrough I changed heap size in the project setting.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I need more information.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;how to use malloc function for make 128KB buffer.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I am using nrf52840,&amp;nbsp;&lt;/span&gt;&lt;span&gt;segger embedded studio V5.32a&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Memory allocation limitations on the nRF52840?</title><link>https://devzone.nordicsemi.com/thread/143968?ContentTypeID=1</link><pubDate>Mon, 13 Aug 2018 12:55:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:070e80ab-a1f6-47fa-99ca-66f9d6aaf7bb</guid><dc:creator>Nicholas Lee</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;
&lt;p&gt;The XXLARGE block is defined in the sdk_config.h file as 3444 bytes, which is a strange and arbitrary number. I had assumed the smaller blocks would be fractions of that.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Memory allocation limitations on the nRF52840?</title><link>https://devzone.nordicsemi.com/thread/143862?ContentTypeID=1</link><pubDate>Mon, 13 Aug 2018 08:09:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8cc283d7-b9ac-4f44-9506-91a57102171e</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I agree that it would make sense to let any unused memory be part of the heap. You can achieve it by editing the section placement file (flash_placement.xml in the SDK projects). Replace the existing line that sets the heap (&lt;code&gt;name=&amp;quot;.heap&amp;quot;&lt;/code&gt;) with the following line:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="xml"&gt;    &amp;lt;ProgramSection alignment=&amp;quot;4&amp;quot; size=&amp;quot;((__RAM_segment_end__ - __STACKSIZE__) - __heap_load_start__)&amp;quot; load=&amp;quot;No&amp;quot; name=&amp;quot;.heap&amp;quot; /&amp;gt;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;nrf_malloc&lt;/code&gt; function is part of the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.0.0/lib_mem_manager.html?cp=4_0_0_3_29"&gt;Memory Manager&lt;/a&gt;&amp;nbsp;library, which is more complex than the standard malloc function. The fixed size blocks&amp;nbsp;are used to&amp;nbsp;reduce&amp;nbsp;memory fragmentation. The buffer sizes are configurable in the projects sdk_config.h (e.g. &lt;code&gt;MEMORY_MANAGER_XXSMALL_BLOCK_SIZE&lt;/code&gt;). Where do you see that the buffer size increments are based on fractions of&amp;nbsp;3444?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Memory allocation limitations on the nRF52840?</title><link>https://devzone.nordicsemi.com/thread/143735?ContentTypeID=1</link><pubDate>Fri, 10 Aug 2018 13:12:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6638bd4-3568-449c-b1a9-fd869e78bb12</guid><dc:creator>Nicholas Lee</dc:creator><description>&lt;p&gt;Thank you. &lt;br /&gt;Yes, changing that Heap Size value to 128KB now allows me to allocate sensibly sized arrays.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t understand why this Heap Size value is set in this obscure settings dialog as an arbitrary and tiny default value, instead of being automatically sized to be whatever the free memory for the chip is.&lt;br /&gt;&lt;br /&gt;Also, can you shed any light on the&amp;nbsp;&lt;span&gt;nrf_malloc function? Is there any advantage to using that over malloc?&lt;br /&gt;&lt;/span&gt;Why are the &lt;span&gt;nrf_malloc&amp;nbsp;&lt;/span&gt;buffer size increments based on fractions of 3444 instead of some power-of-2 number of bytes. Does this perhaps relate to some common application for this function?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Memory allocation limitations on the nRF52840?</title><link>https://devzone.nordicsemi.com/thread/143670?ContentTypeID=1</link><pubDate>Fri, 10 Aug 2018 07:44:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:552dea0f-0bab-4da4-85b0-bf398ccd1bc3</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You can set the heap (and stack) size under &amp;quot;Runtime Memory Area&amp;quot; in the project settings:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/500x0/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-12837342105e446da1f1845c9f1b10c4/ses_5F00_stack_5F00_heap_5F00_marked.PNG" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;The longer story is that what you select above is put in the __HEAPSIZE__ and&amp;nbsp;__STACKSIZE__ variable, which are used in the&amp;nbsp;section-placement file. In the SDK examples this is called flash_placement.xml and is in the same directory as the project files for all SDK examples. Relevant snippet:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="xml"&gt;    &amp;lt;ProgramSection alignment=&amp;quot;4&amp;quot; size=&amp;quot;__HEAPSIZE__&amp;quot; load=&amp;quot;No&amp;quot; name=&amp;quot;.heap&amp;quot; /&amp;gt;
    &amp;lt;ProgramSection alignment=&amp;quot;8&amp;quot; size=&amp;quot;__STACKSIZE__&amp;quot; load=&amp;quot;No&amp;quot; place_from_segment_end=&amp;quot;Yes&amp;quot; name=&amp;quot;.stack&amp;quot;  address_symbol=&amp;quot;__StackLimit&amp;quot; &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Memory allocation limitations on the nRF52840?</title><link>https://devzone.nordicsemi.com/thread/143655?ContentTypeID=1</link><pubDate>Fri, 10 Aug 2018 06:28:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0cd04061-681f-469e-83d0-d2d050bdb68d</guid><dc:creator>Olaf</dc:creator><description>&lt;p&gt;Hi did you set the heap size correctly?&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/36578/memory-management-heap"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/36578/memory-management-heap&lt;/a&gt;&amp;nbsp;BR Olaf&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>