<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: How many free memories are there when Maply starts?</title>
		<link>http://forums.leaflabs.com/topic.php?id=13341</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:20:21 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=13341" rel="self" type="application/rss+xml" />

		<item>
			<title>gbulmer on "How many free memories are there when Maply starts?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13341#post-28380</link>
			<pubDate>Fri, 09 Aug 2013 07:19:22 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">28380@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;joyzhou - That's a very interesting result. Thank you for sharing.&#60;/p&#62;
&#60;p&#62;It's a bit disappointing, I did expect more.&#60;br /&#62;
Did you try starting at too big a value? The idea is to see if the initial malloc's are fragmenting memory.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;// The code(in setup):

        int i;
	void * p;
	for(i=20*1024; i&#38;gt;1024;i--){
		SerialUSB.print(i);
		p = malloc(i);
		if(p==NULL){
			SerialUSB.println(&#38;quot;\t failed&#38;quot;);
			continue;
		}
		else{
			SerialUSB.println(&#38;quot;\tOK&#38;quot;);
			free(p);
                        delay(100);
		}
	}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>joyzhou on "How many free memories are there when Maply starts?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13341#post-28373</link>
			<pubDate>Thu, 08 Aug 2013 19:13:46 +0000</pubDate>
			<dc:creator>joyzhou</dc:creator>
			<guid isPermaLink="false">28373@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer - Thank you for the suggestions.&#60;/p&#62;
&#60;p&#62;I simplified the sketch.&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;// The code(in setup):

        int i;
	void * p;
	for(i=1024;i&#38;lt;20*1024;i++){
		SerialUSB.print(i);
		p = malloc(i);
		if(p==NULL){
			SerialUSB.println(&#38;quot;\t failed&#38;quot;);
			break;
		}
		else{
			SerialUSB.println(&#38;quot;\tOK&#38;quot;);
			free(p);
		}
	}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;The result:&#60;br /&#62;
...&#60;br /&#62;
...&#60;br /&#62;
13562   OK&#60;br /&#62;
13563   OK&#60;br /&#62;
13564   OK&#60;br /&#62;
13565   OK&#60;br /&#62;
13566    failed&#60;/p&#62;
&#60;p&#62;That is, when a simplest program starts, there are at least 13566 bytes of *continuous* RAM. The total free RAM may be larger.&#60;/p&#62;
&#60;p&#62;I will modify the code to solve the problem.&#60;/p&#62;
&#60;p&#62;(Edit: I added code quotes to make it easier to read. I hope that is okay. gbulmer)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "How many free memories are there when Maply starts?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13341#post-28370</link>
			<pubDate>Thu, 08 Aug 2013 07:12:17 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">28370@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;joyzhou - I'd suggest you make setup() simpler, and more likely to work, so that you can isolate the bug.&#60;br /&#62;
For example:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;#define BUF_SIZE 10

void setup(void) {
	pinMode(BOARD_LED_PIN, OUTPUT);
	SerialUSB.begin();
	pinMode(BOARD_BUTTON_PIN, INPUT);

	while(!isButtonPressed()){
		toggleLED();
		delay(200);
	}

        unsigned int asize = BUF_SIZE * sizeof(kiss_fft_scalar);
        SerialUSB.print(&#38;quot;size of allocation =&#38;quot;);
        SerialUSB.println(asize);

	kiss_fft_scalar * rin =(kiss_fft_scalar*) malloc(asize);

	if(rin == NULL ){
		SerialUSB.println(&#38;quot;mycfg failed.&#38;quot;);
		return;
	}
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;There are conflicting documents for malloc(), one says it doesn't work:&#60;br /&#62;
&#60;a href=&#34;http://leaflabs.com/docs/language-index.html?highlight=malloc&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/language-index.html?highlight=malloc&#60;/a&#62;&#60;br /&#62;
and the other says it does:&#60;br /&#62;
&#60;a href=&#34;http://leaflabs.com/docs/faq.html?highlight=malloc&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/faq.html?highlight=malloc&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;I never use it, so I'm not sure which applies (I thought it did work, but I can't remember why).&#60;/p&#62;
&#60;p&#62;Edit: I haven't checked but I would guess at least 16KB would be free.&#60;br /&#62;
It may not be working because the 'premain' initialisation might be incorrect, but I don't know that is the case. You might try a dumb program, only with setup() and loop(), using the Maple IDE to see if it makes a difference.&#60;/p&#62;
&#60;p&#62;(Full disclosure: I am not a member of LeafLabs staff.)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>joyzhou on "How many free memories are there when Maply starts?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13341#post-28367</link>
			<pubDate>Thu, 08 Aug 2013 03:34:08 +0000</pubDate>
			<dc:creator>joyzhou</dc:creator>
			<guid isPermaLink="false">28367@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello everyone.&#60;br /&#62;
I am trying to do some FFT on maple_mini with the kiss_fft.&#60;br /&#62;
The program always failes to malloc(1024*sizeof(float)),&#60;br /&#62;
while the maple mini has 20KB of RAM. Why?&#60;br /&#62;
Here is the code:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;#include &#38;lt;math.h&#38;gt;
#include &#38;lt;stdlib.h&#38;gt;
#include &#38;lt;wirish/wirish.h&#38;gt;
#include &#38;quot;kiss_fftr.h&#38;quot;

#define BUF_SIZE 1024

void setup(void) {
	pinMode(BOARD_LED_PIN, OUTPUT);
	SerialUSB.begin();
	pinMode(BOARD_BUTTON_PIN, INPUT);

	while(!isButtonPressed()){
		toggleLED();
		delay(200);
	}

	kiss_fftr_cfg mycfg = kiss_fftr_alloc(BUF_SIZE, 0, NULL, NULL);
	kiss_fft_scalar * rin =(kiss_fft_scalar*) malloc(BUF_SIZE * sizeof(kiss_fft_scalar));
	kiss_fft_cpx * fout = (kiss_fft_cpx*) malloc((BUF_SIZE/2+1) * sizeof(kiss_fft_cpx));
	if(mycfg == NULL ){
		SerialUSB.println(&#38;quot;mycfg failed.&#38;quot;);
		return;
	}
	if(rin == NULL){
		SerialUSB.println(&#38;quot;rin failed.&#38;quot;);
		return;
	}
	if(fout == NULL){
		SerialUSB.println(&#38;quot;fout failed.&#38;quot;);
		return;
	}
	SerialUSB.println(&#38;quot;allocations OK.&#38;quot;);

	for(int i=0;i&#38;lt;BUF_SIZE;i++){
		rin[i] = sin((float)i/20.0f) + 0.5*cos((float)i/30.0f);
	}
	unsigned long t0, t1;
	t0 = micros();
	kiss_fftr(mycfg, rin, fout);
	t1 = micros();
	SerialUSB.println(t1 - t0);
	kiss_fftr_free(mycfg);
	free(rin);
	free(fout);

}

void loop(void) {

	digitalWrite(BOARD_LED_PIN, HIGH);
	delay(50);
	digitalWrite(BOARD_LED_PIN, LOW);
	delay(800);
}

__attribute__((constructor)) void premain() {
    init();
}

int main(void) {
    setup();
    while (true) {
        loop();
    }
    return 0;
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>

	</channel>
</rss>
