<?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 are variables stored in the RAM? Memory usage issue...</title>
		<link>http://forums.leaflabs.com/topic.php?id=1181</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:07:56 +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=1181" rel="self" type="application/rss+xml" />

		<item>
			<title>gbulmer on "How are variables stored in the RAM? Memory usage issue..."</title>
			<link>http://forums.leaflabs.com/topic.php?id=1181#post-7224</link>
			<pubDate>Wed, 23 Nov 2011 20:09:20 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">7224@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;&#34;How much space do global variables like uint8 take?&#34;&#60;br /&#62;
Strictly, IIRC it depends on the flags given to the compiler, or can be set on a variable by variable basis using a 'pragma' to the compiler. &#60;/p&#62;
&#60;p&#62;The processor is capable of loading and storing memory in one, two, four or eight byte units, which can be aligned on any byte memory address. So the data can be packed, and the CPU will handle it. AFAIK, the default to the compiler is to pack data.&#60;/p&#62;
&#60;p&#62;&#34;Is a separate uint8 beeing stored in a 4-byte-Integer memory adress?&#34;&#60;br /&#62;
No, it will be one byte unless you force 4 byte alignment using compiler flags or a 'pragma'.&#60;/p&#62;
&#60;p&#62;&#34;How is an array of chars put into memory?&#34;&#60;br /&#62;
Characters in a character array are stored in consecutive byte addresses.&#60;/p&#62;
&#60;p&#62;&#34;Each of the 32-bit memory registers four chars?&#34;&#60;br /&#62;
Memory is not registers. Registers are part of the processor.&#60;br /&#62;
Memory is accessed in units of bytes.&#60;/p&#62;
&#60;p&#62;Like many things, you can test this for yourself, by doing something like:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;char a;
char b;
char c[10];

void setup() {
}

void loop() {
  SerialUSB.println((unsigned int)&#38;amp;a, HEX);
  SerialUSB.println((unsigned int)&#38;amp;b, HEX);
  SerialUSB.println((unsigned int)&#38;amp;c[0], HEX);
  SerialUSB.println((unsigned int)&#38;amp;c[1], HEX);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;which will print the memory addresses of the &#60;code&#62;char&#60;/code&#62; variables and consecutive characters in the array.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>HDS on "How are variables stored in the RAM? Memory usage issue..."</title>
			<link>http://forums.leaflabs.com/topic.php?id=1181#post-7208</link>
			<pubDate>Mon, 21 Nov 2011 03:32:00 +0000</pubDate>
			<dc:creator>HDS</dc:creator>
			<guid isPermaLink="false">7208@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi, all, have concerns on the memory usage.&#60;br /&#62;
How much space do global variables like uint8 take?&#60;br /&#62;
Is a separate uint8 beeing stored in a 4-byte-Integer memory adress?&#60;/p&#62;
&#60;p&#62;If so, it would make no sense to use those data types, where thy aren't absolutely necessary, but better use an int32 or uint32 instead.&#60;/p&#62;
&#60;p&#62;How is an array of chars put into memory?&#60;br /&#62;
Each of the 32-bit memory registers four chars?&#60;/p&#62;
&#60;p&#62;Do I have to use &#34;packed&#34; also for a char array to use memory efficiantly?
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
