<?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>Problems with using float malloc()</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/94699/problems-with-using-float-malloc</link><description>HI 
 chip : NRF52832 
 tool : segger embedded studio 
 SDK : 17.0.0 
 
 I have a problem using malloc(). I simply tested it like this: 
 #define ds_len 500 
 float* test_data= (float*)malloc(sizeof(float)*ds_len); 
 for(i=0; i&amp;lt;ds_len;i++) 
 { 
 test_data</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 15 Dec 2022 05:09:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/94699/problems-with-using-float-malloc" /><item><title>RE: Problems with using float malloc()</title><link>https://devzone.nordicsemi.com/thread/400740?ContentTypeID=1</link><pubDate>Thu, 15 Dec 2022 05:09:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ea7fc8a-6ccc-422f-8e02-59fdcb3aa24a</guid><dc:creator>cabin</dc:creator><description>&lt;p&gt;I have identified what is the problem.&lt;/p&gt;
&lt;p&gt;Thank you&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;have nice day.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with using float malloc()</title><link>https://devzone.nordicsemi.com/thread/400588?ContentTypeID=1</link><pubDate>Wed, 14 Dec 2022 11:32:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:11aaba27-cf6d-45cc-a091-4a33063dd27d</guid><dc:creator>Naeem Maroof</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I am not able to run your project. Nonetheless, upon inspection I can see that you are using the same code in the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;main.c&lt;/span&gt; file as you have mentioned in your original post.&lt;/p&gt;
&lt;p&gt;However, I am able to allocate floating point variables using malloc and then store values in them and then read and display (see the snapshot below). However, as I mentioned earlier, I was getting issues of printing floating point variables, so I have reverted to using NRF_LOG_FLOAT macro to print floating point on the console.&lt;/p&gt;
&lt;p&gt;You can see in the code that the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;temp&lt;/span&gt; is a floating point variables which should contain the values read from the allocated memory for float (that is from the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;test_data&lt;/span&gt;).&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1671017453266v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Naeem&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with using float malloc()</title><link>https://devzone.nordicsemi.com/thread/400027?ContentTypeID=1</link><pubDate>Mon, 12 Dec 2022 01:12:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4a810d31-3d41-48e4-b648-56992ac274c8</guid><dc:creator>cabin</dc:creator><description>&lt;p&gt;HI&lt;br /&gt; I can print without using malloc.&lt;br /&gt;I will send you the project file.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with using float malloc()</title><link>https://devzone.nordicsemi.com/thread/399976?ContentTypeID=1</link><pubDate>Fri, 09 Dec 2022 15:10:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1640f70c-03c3-4b89-abeb-26879f060079</guid><dc:creator>Naeem Maroof</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thank you for contacting DevZone at NordicSemi.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I think the problem you are experiencing is about the formatting using printing statements.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Can you try printing a floating-point number without using malloc (by direct variable assignment)?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If you fell okay, then pls send me your code (as a project).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Naeem&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>