Here is my next try. Based on the know how from which place a particular value needs to replaced. This requires an explicit loop and some temp integers as well. Still in Perl but easy to translate to C and pointer arithmetics.

use strict; use warnings; my @buffer = qw[X0 X1 X2 X3 X4 Y0 Y1 Y2 Y3 Y4 Y5 Y6 Y7]; sub swapbuffers { my ($n1, $buf) = @_; my $n2 = @$buf-$n1; my $here = 0; my $tmp = $$buf[$here]; my $istart = $here; for (0..@$buf-1) { my $from = $here < $n2 ? $here+$n1 : $here-$n2; if( $from == $istart ) { # loop finished $$buf[$here] = $tmp; $here = ++$istart; $tmp = $$buf[$istart] } else { $$buf[$here] = $$buf[$from]; $here = $from; } print "@$buf\n"; } } print "@buffer\n"; swapbuffers 5, \@buffer; print "@buffer\n";

In reply to Re^5: [OT] Swapping buffers in place. by hdb
in thread [OT] Swapping buffers in place. by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.