<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>MQX Software SolutionsのトピックMQX malloc</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-malloc/m-p/460388#M15449</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is it possible to use malloc inside MQX / MQX Lite task?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried it but malloc returns NULL pointer all the time.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 30 Dec 2015 21:06:29 GMT</pubDate>
    <dc:creator>martindusek</dc:creator>
    <dc:date>2015-12-30T21:06:29Z</dc:date>
    <item>
      <title>MQX malloc</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-malloc/m-p/460388#M15449</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is it possible to use malloc inside MQX / MQX Lite task?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried it but malloc returns NULL pointer all the time.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Dec 2015 21:06:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-malloc/m-p/460388#M15449</guid>
      <dc:creator>martindusek</dc:creator>
      <dc:date>2015-12-30T21:06:29Z</dc:date>
    </item>
    <item>
      <title>Re: MQX malloc</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-malloc/m-p/460389#M15450</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Martin, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I never used malloc() into a MQX (lite) task but maybe you should use mem_alloc() instead of the standard malloc() function. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regard. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Max. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Dec 2015 01:19:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-malloc/m-p/460389#M15450</guid>
      <dc:creator>mr_max</dc:creator>
      <dc:date>2015-12-31T01:19:41Z</dc:date>
    </item>
    <item>
      <title>Re: MQX malloc</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-malloc/m-p/460390#M15451</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Martin:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Freescale &lt;SPAN class="&amp;amp;quothighlight&amp;quot;"&gt;&lt;STRONG&gt;MQX&lt;/STRONG&gt;&lt;/SPAN&gt; uses its own memory allocation system, which doesn't rely on heap.&lt;/P&gt;&lt;P&gt;The default &lt;SPAN class="&amp;amp;quothighlight&amp;quot;"&gt;&lt;STRONG&gt;MQX&lt;/STRONG&gt;&lt;/SPAN&gt; memory pool, where &lt;SPAN class="&amp;amp;quothighlight&amp;quot;"&gt;&lt;STRONG&gt;MQX&lt;/STRONG&gt;&lt;/SPAN&gt; kernel allocates system memory, is between &lt;/P&gt;&lt;P&gt;__KERNEL_DATA_START and __KERNEL_DATA_END (symbols generated during bsp linkage).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It allocates memory using function _mem_alloc_system().&lt;/P&gt;&lt;P&gt;On top of this, in bsp we define malloc() to call _mem_alloc_system().&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want the &lt;SPAN class="&amp;amp;quothighlight&amp;quot;"&gt;&lt;STRONG&gt;MQX&lt;/STRONG&gt;&lt;/SPAN&gt; kernel to call Thumb library malloc, then you have to define&lt;/P&gt;&lt;P&gt;_mem_alloc_system* in preprocessor to be &lt;SPAN class="&amp;amp;quothighlight&amp;quot;"&gt;&lt;STRONG&gt;malloc&lt;/STRONG&gt;&lt;/SPAN&gt; #define _mem_alloc_system &lt;SPAN class="&amp;amp;quothighlight&amp;quot;"&gt;&lt;STRONG&gt;malloc&lt;/STRONG&gt;&lt;/SPAN&gt; and so on.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and then disable bsp "duplicate" definition of &lt;SPAN class="&amp;amp;quothighlight&amp;quot;"&gt;&lt;STRONG&gt;malloc&lt;/STRONG&gt;&lt;/SPAN&gt; (either by link order or be removing the duplcate definition from the sources).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to use Thumb library allocation system, you can, but it is your responsibility&lt;/P&gt;&lt;P&gt;to give the CodeWarrior necesarry linker generated files and so on, whatever the Thumb library allocation system relies on. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You loose TAD, kernel logging and other &lt;SPAN class="&amp;amp;quothighlight&amp;quot;"&gt;&lt;STRONG&gt;MQX&lt;/STRONG&gt;&lt;/SPAN&gt; features related to memory allocation. &lt;/P&gt;&lt;P&gt;Have a nice day!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Dec 2015 01:54:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-malloc/m-p/460390#M15451</guid>
      <dc:creator>danielchen</dc:creator>
      <dc:date>2015-12-31T01:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: MQX malloc</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-malloc/m-p/460391#M15452</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't mind what kind of malloc I use. My problem is that calling malloc in mqx lite task returns NULL pointer all the time. I use Processor Expert and Kinetis Design Studio.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In CPU component / Build options / Generate linker file I set heap size. Then I use malloc in main function of my project. It works. But when I use malloc in my mqx lite task (there is only one in the project) the malloc always returns NULL pointer. Why and how to fix it?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Dec 2015 10:26:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-malloc/m-p/460391#M15452</guid>
      <dc:creator>martindusek</dc:creator>
      <dc:date>2015-12-31T10:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: MQX malloc</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-malloc/m-p/460392#M15453</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Martin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I got the same problems of you with MQX Lite + KSDK + PEx. But I finally found how to do it. To make it work, you need to edit &lt;SPAN style="font-family: andale mono,times;"&gt;lite_config.h&lt;/SPAN&gt; header file locate at "&lt;SPAN style="font-family: andale mono,times;"&gt;/SDK/rtos/mqx/config/common/lite_config.h"&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt; in your KDS project explorer. Open it. &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;Near line 63 you should have this : &lt;/SPAN&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14516984060456156 jive_text_macro" data-renderedposition="135.5_8_1232_48" jivemacro_uid="_14516984060456156"&gt;&lt;P&gt;#ifndef MQXCFG_ALLOCATOR&lt;/P&gt;&lt;P&gt;#define MQXCFG_ALLOCATOR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MQX_ALLOCATOR_NONE&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;Now change define by : &lt;/SPAN&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14516984170826902" data-renderedposition="225.5_8_1232_48" jivemacro_uid="_14516984170826902"&gt;&lt;P&gt;#ifndef MQXCFG_ALLOCATOR&lt;/P&gt;&lt;P&gt;#define MQXCFG_ALLOCATOR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MQX_ALLOCATOR_LWMEM&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now when you allocate memory by using &lt;SPAN style="font-family: andale mono,times;"&gt;OSA_MemAlloc()&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;method &lt;SPAN style="font-family: andale mono,times;"&gt;from fsl_os_abstraction&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;, your pointer should return a 32 bits address. &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;I did some test with 2x8bytes memory allocation. The address show below correspond to my two address pointers after &lt;SPAN style="font-family: andale mono,times;"&gt;OSA_MemAlloc()&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;&lt;SPAN class="lia-inline-image-display-wrapper" image-alt="Capture d’écran 2016-01-02 à 00.03.37.png"&gt;&lt;IMG alt="Capture d’écran 2016-01-02 à 00.03.37.png" src="https://community.nxp.com/t5/image/serverpage/image-id/33833i457A5C558C220590/image-size/large?v=v2&amp;amp;px=999" title="Capture d’écran 2016-01-02 à 00.03.37.png" /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;Even &lt;SPAN style="font-family: andale mono,times;"&gt;OSA_FreeMem()&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;work also very well. &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;The only thing that I don't understand yet is why an allocation of 8 bytes have the same address gap than 16 bytes ? See below : &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;&lt;SPAN class="lia-inline-image-display-wrapper" image-alt="Capture d’écran 2016-01-02 à 00.09.21.png"&gt;&lt;IMG alt="Capture d’écran 2016-01-02 à 00.09.21.png" src="https://community.nxp.com/t5/image/serverpage/image-id/33869i6A0EF124EDD9E419/image-size/large?v=v2&amp;amp;px=999" title="Capture d’écran 2016-01-02 à 00.09.21.png" /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;Even worst, if allocate just 1 byte, the gap between two allocations will be 16 address ... Does the MCU will lost these memory space ? &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Nov 2020 13:23:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-malloc/m-p/460392#M15453</guid>
      <dc:creator>mr_max</dc:creator>
      <dc:date>2020-11-02T13:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: MQX malloc</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-malloc/m-p/460393#M15454</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have faced the same problem using MQX Lite with Processor Expert (without SDK). Malloc() worked outside MQX Lite tasks, but not in them. A possible solution is to use MQX Lite's own memory allocation features (lwmem), which are used very similarly to standard malloc() and free(). To use lwmem, do the following:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;In PEx, in the CPU component, go to Build options &amp;gt; Generate linker file and set an appropriate Heap size (e.g. 0x0200).&lt;/LI&gt;&lt;LI&gt;In the MQX Lite PEx component, under Configuration parameters, turn on Lightweight Memory Allocation.&lt;/LI&gt;&lt;LI&gt;Inside the MQX Lite tasks, use these functions for memory management:&lt;UL&gt;&lt;LI&gt;pinter _lwmem_alloc(_mem_size requested_size) - to allocate memory,&lt;/LI&gt;&lt;LI&gt;_mqx_uint _lwmem_free(pointer mem_ptr) - to free memory.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jun 2016 13:03:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-malloc/m-p/460393#M15454</guid>
      <dc:creator>danielnagy</dc:creator>
      <dc:date>2016-06-06T13:03:17Z</dc:date>
    </item>
  </channel>
</rss>

