Shop OBEX P1 Docs P2 Docs Learn Events
How will longfill overwrite in this program? — Parallax Forums

How will longfill overwrite in this program?

jacksonsjacksons Posts: 7
edited 2014-06-06 16:20 in Propeller 1
If I have a program such as this:
VAR
  long buffer[100]
PUB main
  long sensorval := 'get sensor reading
  longmove(@buffer+1, @buffer, 99)
  buffer[0] = sensorval

I was wondering if longfill would actually shift the array or overwrite it in an unexpected way.

Comments

  • T ChapT Chap Posts: 4,223
    edited 2014-06-06 08:35
    Welcome Jacksons. Why not just shift with long move then put the new sensor value at element 99 of the array? I haven't testing longmove in the direction you are trying to go.
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-06-06 08:35
    longmove checks the starting addresses of the two buffers, and will begin copying from either the beginning or the end depending on the order of the addresses. This makes it possible to shift the contents of an array. At least that's the way I understand it. You should test it to make sure.

    EDIT: You did mean to say longmove, and not longfill in your last sentence, right?
  • ElectrodudeElectrodude Posts: 1,658
    edited 2014-06-06 08:42
    It will shift the array as you would expect and not overwrite it. The spin interpreter automatically figures out if it should copy it from bottom to top or top to bottom so bad overwrite things don't happen.

    electrodude

    EDIT: This is what happens when I load twenty tabs and end up taking so long to read them all that I get ninja'd by 7 minutes. Maybe I should reload before posting next time...
  • T ChapT Chap Posts: 4,223
    edited 2014-06-06 08:54
    Thanks for the correction Electro.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-06-06 08:56
    I've tested this many times myself. The various "xxxxMove" statements work great when shifting an array. As Electrodude said, the Spin interpreter makes sure it preserves the data.

    I used to frequently make use of the move statements until Phil exhorted someone doing the same to learn to use a circular buffer. Since taking Phil's advice (to someone else) I find I don't need to shift buffers with "move" statements much.
  • kuronekokuroneko Posts: 3,623
    edited 2014-06-06 16:20
    You also want either longmove(@buffer/COLOR]1[COLOR="#FF0000", @buffer, 99) or longmove(@buffer+4, @buffer, 99).
Sign In or Register to comment.