<?xml version="1.0" encoding="UTF-8"?><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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>Comments on: E10 pointers</title>
	<atom:link href="https://www.emblogic.com/blog/07/e10-pointers/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.emblogic.com/blog/07/e10-pointers/</link>
	<description>Embedded System and ARM Training</description>
	<lastBuildDate>Mon, 07 Oct 2013 04:00:03 +0000</lastBuildDate>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.1</generator>
	<item>
		<title>By: varun.singh</title>
		<link>https://www.emblogic.com/blog/07/e10-pointers/#comment-1001</link>
		<dc:creator><![CDATA[varun.singh]]></dc:creator>
		<pubDate>Fri, 20 Jul 2012 08:04:51 +0000</pubDate>
		<guid isPermaLink="false">http://emblogic.org/blog/?p=4016#comment-1001</guid>
		<description><![CDATA[malloc (memory allocation) is used to dynamically allocate memory from the heap at run time.
eg.
The simplest way to reserve memory is to code something like:
main()
        {
            char string[1000];

            strcpy (string, &quot;some text&quot;);
}
The example above has two problems:

If the data is less than 1000 bytes we are wasting memory.
If the data is greater than 1000 bytes the program is going to crash.
The 1000 bytes are reserved throught out the life of the program. If this was a long running program that rarely used the memory, it would again be wasteful.
so we use malloc()
       malloc allows us to allocate exactly the correct amount of memory 

Library:   stdlib.h
Prototype: void *malloc(size_t size);
Syntax:    char * String;
String = (char *) malloc(1000);

Looking at the example syntax above, 1000 bytes are reserved and the pointer String points to the first byte. The 1000 bytes are NOT initialized by malloc. If the memory is NOT available, a NULL pointer is returned.
the cast is required to return a pointer of the correct type.]]></description>
		<content:encoded><![CDATA[<p>malloc (memory allocation) is used to dynamically allocate memory from the heap at run time.<br />
eg.<br />
The simplest way to reserve memory is to code something like:<br />
main()<br />
        {<br />
            char string[1000];</p>
<p>            strcpy (string, &#8220;some text&#8221;);<br />
}<br />
The example above has two problems:</p>
<p>If the data is less than 1000 bytes we are wasting memory.<br />
If the data is greater than 1000 bytes the program is going to crash.<br />
The 1000 bytes are reserved throught out the life of the program. If this was a long running program that rarely used the memory, it would again be wasteful.<br />
so we use malloc()<br />
       malloc allows us to allocate exactly the correct amount of memory </p>
<p>Library:   stdlib.h<br />
Prototype: void *malloc(size_t size);<br />
Syntax:    char * String;<br />
String = (char *) malloc(1000);</p>
<p>Looking at the example syntax above, 1000 bytes are reserved and the pointer String points to the first byte. The 1000 bytes are NOT initialized by malloc. If the memory is NOT available, a NULL pointer is returned.<br />
the cast is required to return a pointer of the correct type.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
