<?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: Using memcpy on arrays</title>
		<link>http://forums.leaflabs.com/topic.php?id=10136</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:14:04 +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=10136" rel="self" type="application/rss+xml" />

		<item>
			<title>pyrohaz on "Using memcpy on arrays"</title>
			<link>http://forums.leaflabs.com/topic.php?id=10136#post-22065</link>
			<pubDate>Mon, 21 Jan 2013 14:06:58 +0000</pubDate>
			<dc:creator>pyrohaz</dc:creator>
			<guid isPermaLink="false">22065@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thats really useful actually, all of my arrays are 64 pieces of data but by using size of, that eases things by a lot! Thanks for that :)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Using memcpy on arrays"</title>
			<link>http://forums.leaflabs.com/topic.php?id=10136#post-22062</link>
			<pubDate>Mon, 21 Jan 2013 10:16:35 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">22062@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;pyrohaz - I'd like to suggest a slightly more robust approach to copying memory.&#60;/p&#62;
&#60;p&#62;Instead of &#60;code&#62;memcpy(array1, array2, 128);&#60;/code&#62;&#60;br /&#62;
do &#60;code&#62;memcpy(array1, array2, sizeof(array1));&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;&#60;code&#62;sizeof&#60;/code&#62; is applied to the destination of the &#60;code&#62;memcpy&#60;/code&#62;.&#60;/p&#62;
&#60;p&#62;Arduino (AVR, ATmega) and Maple (ARM, STM32) have different sizes for data types, for example &#60;code&#62;int&#60;/code&#62;, so using a fixed value might not work when porting code. The compiler calculates &#60;code&#62;sizeof()&#60;/code&#62; at compile time, and ensures the value is the actual size of the variable, which is more robust when porting code. &#60;code&#62;sizeof()&#60;/code&#62; can be used in calculations, e.g. &#60;code&#62;sizeof(array1)-1&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;NB, for folks who aren't familiar with sizeof; sizeof calculates the size of the value stored in the variable, sizeof does not calculate the size of object a variable may point at:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;char array1[130];
char *p = array1;
char array2[130];
memcpy(p, array2, sizeof(p));&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;will only copy the size of a char pointer (4 bytes on STM32), and not the size of the array p is pointing to.&#60;br /&#62;
&#60;code&#62;memcpy(p, array2, sizeof(*p));&#60;/code&#62;&#60;br /&#62;
copies 1 byte.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>pyrohaz on "Using memcpy on arrays"</title>
			<link>http://forums.leaflabs.com/topic.php?id=10136#post-22061</link>
			<pubDate>Mon, 21 Jan 2013 09:25:36 +0000</pubDate>
			<dc:creator>pyrohaz</dc:creator>
			<guid isPermaLink="false">22061@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Heh! Brilliant, thats sorted it, I never needed to do that on arduino haha thanks a lot dude! :)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bubulindo on "Using memcpy on arrays"</title>
			<link>http://forums.leaflabs.com/topic.php?id=10136#post-22060</link>
			<pubDate>Mon, 21 Jan 2013 09:03:41 +0000</pubDate>
			<dc:creator>bubulindo</dc:creator>
			<guid isPermaLink="false">22060@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;did you include string.h? &#60;/p&#62;
&#60;p&#62;This compiles for me: &#60;/p&#62;
&#60;p&#62;#include &#38;lt;string.h&#38;gt;     &#38;lt;------ THIS?? &#60;/p&#62;
&#60;p&#62;void setup(){}&#60;/p&#62;
&#60;p&#62;void loop(){&#60;/p&#62;
&#60;p&#62;char array1[130];&#60;br /&#62;
char array2[130];&#60;/p&#62;
&#60;p&#62;memcpy(array1, array2, 128);&#60;br /&#62;
}
&#60;/p&#62;</description>
		</item>
		<item>
			<title>pyrohaz on "Using memcpy on arrays"</title>
			<link>http://forums.leaflabs.com/topic.php?id=10136#post-22059</link>
			<pubDate>Mon, 21 Jan 2013 07:36:21 +0000</pubDate>
			<dc:creator>pyrohaz</dc:creator>
			<guid isPermaLink="false">22059@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hey,&#60;br /&#62;
As you can probably tell from my questions, i'm porting from arduino to maple. So far so good!&#60;/p&#62;
&#60;p&#62;The only question, on my arduino, I can use the command memcpy to copy a 64 piece array from one section to another, for example:&#60;br /&#62;
memcpy(array1, array2, 128);&#60;/p&#62;
&#60;p&#62;The small snippet of code above will copy array2 to array1.&#60;/p&#62;
&#60;p&#62;When I tried to write this code to my maple, it said that memcpy was not declared in this scope, the arduino IDE allows me to use this piece of code.&#60;/p&#62;
&#60;p&#62;What am I doing wrong?&#60;/p&#62;
&#60;p&#62;Thanks,&#60;br /&#62;
Harris
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
