<?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: ArrayShift in C#</title>
	<atom:link href="http://www.jeremyprivett.com/blog/archives/arrayshift-in-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jeremyprivett.com/blog/archives/arrayshift-in-c/</link>
	<description>Programming and Life</description>
	<lastBuildDate>Tue, 29 Sep 2009 22:01:20 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Steven</title>
		<link>http://www.jeremyprivett.com/blog/archives/arrayshift-in-c/comment-page-1/#comment-136253</link>
		<dc:creator>Steven</dc:creator>
		<pubDate>Tue, 29 Sep 2009 22:01:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeremyprivett.com/blog/?p=424#comment-136253</guid>
		<description>Mentioned this over AIM, but I&#039;ll repost for everyone. Looks less ugly and doesn&#039;t require &quot;unsafe&quot; code.

public static T ArrayShift(ref T[] array)
{
  T first = array[0];
  // (src, srcStartIndex, dest, destStartIndex, itemsToCopy)
  System.Array.Copy(array, 1, array, 0, array.Length - 1);
  return first;
}

I&#039;m sure System.Array.Copy handles the pointers and memcpy/memmove internally.</description>
		<content:encoded><![CDATA[<p>Mentioned this over AIM, but I&#8217;ll repost for everyone. Looks less ugly and doesn&#8217;t require &#8220;unsafe&#8221; code.</p>
<p>public static T ArrayShift(ref T[] array)<br />
{<br />
  T first = array[0];<br />
  // (src, srcStartIndex, dest, destStartIndex, itemsToCopy)<br />
  System.Array.Copy(array, 1, array, 0, array.Length &#8211; 1);<br />
  return first;<br />
}</p>
<p>I&#8217;m sure System.Array.Copy handles the pointers and memcpy/memmove internally.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steven</title>
		<link>http://www.jeremyprivett.com/blog/archives/arrayshift-in-c/comment-page-1/#comment-136252</link>
		<dc:creator>Steven</dc:creator>
		<pubDate>Tue, 29 Sep 2009 17:11:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeremyprivett.com/blog/?p=424#comment-136252</guid>
		<description>Isn&#039;t there a C# keyword that lets you use pointers in your class/method?

Like,

public static T ArrayShift(T *array)
{
  T first = array[0];
  T[] newArray = new T[ array.Length - 1 ];
  memcpy((void *) newArray, (const void *) (array + 1), sizeof(T) * (array.Length - 1));
  
  // free memory, then reassign it to the new array.
  delete[] array;
  array = newArray;
  
  return first;
}

Something like &quot;array++;&quot; sounds easier, but I&#039;m not sure if it would update the indexes/Length property.</description>
		<content:encoded><![CDATA[<p>Isn&#8217;t there a C# keyword that lets you use pointers in your class/method?</p>
<p>Like,</p>
<p>public static T ArrayShift(T *array)<br />
{<br />
  T first = array[0];<br />
  T[] newArray = new T[ array.Length - 1 ];<br />
  memcpy((void *) newArray, (const void *) (array + 1), sizeof(T) * (array.Length &#8211; 1));</p>
<p>  // free memory, then reassign it to the new array.<br />
  delete[] array;<br />
  array = newArray;</p>
<p>  return first;<br />
}</p>
<p>Something like &#8220;array++;&#8221; sounds easier, but I&#8217;m not sure if it would update the indexes/Length property.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

