<?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>How to use malloc in nRF9160?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/45179/how-to-use-malloc-in-nrf9160</link><description>I can&amp;#39; initialize malloc. Any help? 
 I implement code like bellow.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 20 Mar 2025 17:28:59 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/45179/how-to-use-malloc-in-nrf9160" /><item><title>RE: How to use malloc in nRF9160?</title><link>https://devzone.nordicsemi.com/thread/528274?ContentTypeID=1</link><pubDate>Thu, 20 Mar 2025 17:28:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9fe27ecf-bc07-42f6-bac3-274392e6744d</guid><dc:creator>robbsadler</dc:creator><description>&lt;p&gt;Even now in 2025 in SDK 2.8, I was getting&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;span&gt;undefined reference to `k_malloc&lt;/span&gt;&lt;span&gt;`&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The above suggestion was the solution. It would be helpful if this rule requiring heap space be allocated was mentioned in the compiler error instead of an undefined reference.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use malloc in nRF9160?</title><link>https://devzone.nordicsemi.com/thread/270056?ContentTypeID=1</link><pubDate>Thu, 17 Sep 2020 11:28:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32163bea-072a-46a2-afca-382ae4fbfc38</guid><dc:creator>drunot</dc:creator><description>&lt;p&gt;Have you remembered to allocate heap space? E.g. set &amp;#39;CONFIG_HEAP_MEM_POOL_SIZE&amp;#39; in &amp;#39;prj.conf&amp;#39; to a non zero value?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use malloc in nRF9160?</title><link>https://devzone.nordicsemi.com/thread/267079?ContentTypeID=1</link><pubDate>Sun, 30 Aug 2020 03:32:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d5d967a8-6f4e-4e5c-91ff-d2e3ad82b691</guid><dc:creator>KevinThompson-SR</dc:creator><description>&lt;p&gt;I&amp;#39;m having same exact issue... any resolution or suggestions?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use malloc in nRF9160?</title><link>https://devzone.nordicsemi.com/thread/236410?ContentTypeID=1</link><pubDate>Wed, 26 Feb 2020 05:37:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:07f6c090-4b67-4ea3-b18b-e15d80a55b57</guid><dc:creator>lavande</dc:creator><description>&lt;p&gt;Hi , Martin,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Where is the definition of &amp;#39;k_malloc&amp;#39;?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use malloc in nRF9160?</title><link>https://devzone.nordicsemi.com/thread/215573?ContentTypeID=1</link><pubDate>Thu, 17 Oct 2019 15:16:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6b02180-2168-42f9-bb37-204bc641774e</guid><dc:creator>TBP</dc:creator><description>&lt;p&gt;Hey,&lt;/p&gt;
&lt;p&gt;I tried using k_malloc and got a linking error:&lt;br /&gt;&lt;br /&gt;&amp;nbsp;undefined reference to `k_malloc&lt;span&gt;`&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Is there something else I need to in order to use k_malloc?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Tal&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use malloc in nRF9160?</title><link>https://devzone.nordicsemi.com/thread/177499?ContentTypeID=1</link><pubDate>Thu, 21 Mar 2019 08:49:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a69f0fc3-678c-4c26-b78a-5689f554c0df</guid><dc:creator>Martin Lesund</dc:creator><description>&lt;p&gt;Hello Yusuke,&lt;/p&gt;
&lt;p&gt;I would recommend to &lt;a href="https://docs.zephyrproject.org/latest/reference/kernel/memory/heap.html?highlight=malloc#allocating-memory"&gt;check out the documentation.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You can use &lt;a href="https://docs.zephyrproject.org/latest/reference/kernel/memory/heap.html?highlight=malloc#_CPPv38k_malloc6size_t"&gt;k_malloc&lt;/a&gt;();&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Here is an example on how to allocate memory:&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;char *mem_ptr;

mem_ptr = k_malloc(200);
if (mem_ptr != NULL)) {
    memset(mem_ptr, 0, 200);
    ...
} else {
    printf(&amp;quot;Memory not allocated&amp;quot;);
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>