Re: Results of the memswap() smackdown from the thread "Sorting" assignment



In article <GbGdnb81Zd2MlSvaRVnyjAA@xxxxxx>, Malcolm McLean
<regniztar@xxxxxxxxxxxxxx> writes
Of course after a swap I'd expect x to equal the former value of y and
y to equal x,

Agreed.

which is impossible to achieve if x and y share bytes.

Not quite.

Suppose we are swapping n bytes starting at x and y, where y = x + k and
k < n. Then swapping is possible if, and only if:
for all i in 0 <= i < n-2k:
x [i] = x [i + 2k]

The easiest way to see this is to draw two parallel rows of boxes,
labelled "before" and "after", and link the boxes that must be the same.

--
Clive D.W. Feather | Home: <clive@xxxxxxxxxx>
Tel: +44 20 8495 6138 (work) | Web: <http://www.davros.org>
Fax: +44 870 051 9937 | Work: <clive@xxxxxxxxx>
Please reply to the Reply-To address, which is: <clive@xxxxxxxxxx>
.



Relevant Pages

  • Re: FreeBSD 6.1, crashes and a lack of vmcores
    ... We also ended up swapping that RAM out with another box and the problem did not move to the new box. ... However, as I mentioned earlier, this is one box out of a farm that is acting particularly less stable and all the boxes should ideally be receiving similar traffic loads. ... Disabling ACPI resolved a number of noisy boot time messages, but didn't give us any noticeable edge in stability. ... I suspect I might have inadvertently introduced a negative variable in the drive swapping I did. ...
    (freebsd-hackers)
  • Re: SKY + Installation
    ... Even if it is just swapping ... boxes they have to pay the "engineer" a callout fee. ...
    (uk.media.tv.misc)
  • Re: Is this code valid
    ... > of byte swapping and you see different results on Solaris and Linux ... > boxes. ...
    (comp.lang.c)