News:

  • August 04, 2026, 11:09:03 AM

Login with username, password and session length

Author Topic: Block Copy Nested Structure Fields  (Read 8735 times)

Bolt

  • Hero Member
  • *****
  • Posts: 598
Block Copy Nested Structure Fields
« on: June 06, 2023, 01:17:45 PM »
I'm trying to do a block copy MyStructure0-n.A to MyStructure0-n.B. If it is MyStructureA0-n and MyStructureB0-n it can be done with a MEMCOPY. However, I can't seem to make this nested structure work with a MEMCOPY, MOVER, COPY, etc. The best I can come up with is a FOR/NEXT loop with MOVE MyStructure[V0].A to MyStructure[V0].B. Is there a cleaner way?

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3839
    • Host Engineering
Re: Block Copy Nested Structure Fields
« Reply #1 on: June 06, 2023, 01:33:00 PM »
The "range" behavior with structs must be contiguous, so you can't do that with nested structs since the range of nested is not contiguous in memory.

FOR/NEXT works fine.  That can work just as fast as a supposed "ranged" MEMCOPY of substructs since it would have to do it in pieces/parts, just like you are doing with a FOR/NEXT.

You could stick the FOR/NEXT in a subroutine and it is guaranteed to execute COMPLETELY INTRA-scan, regardless of any ".TimeSlice" of the "calling" code-block (if that's a concern).

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3839
    • Host Engineering
Re: Block Copy Nested Structure Fields
« Reply #2 on: June 06, 2023, 01:40:11 PM »
I just made sure you can do a MEMCOPY of a nested single struct to another nested single struct (both substructs are Timer structs)
MEMCOPY Recipe[V0].CookTimer Other[V0].ChillTimer (Number of Source Elements: 1)

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: Block Copy Nested Structure Fields
« Reply #3 on: June 06, 2023, 02:11:21 PM »
You could stick the FOR/NEXT in a subroutine and it is guaranteed to execute COMPLETELY INTRA-scan, regardless of any ".TimeSlice" of the "calling" code-block (if that's a concern).

That's a perfect solution, that removes the subconscious kludge factor for me, as it can still be performed mid rung, if you will, working the same as a block copy, vs calling it in the next rung or stage, etc.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3839
    • Host Engineering
Re: Block Copy Nested Structure Fields
« Reply #4 on: June 06, 2023, 02:21:06 PM »
That's a perfect solution, that removes the subconscious kludge factor for me, as it can still be performed mid rung, if you will, working the same as a block copy, vs calling it in the next rung or stage, etc.
And you can control when the subroutine gets called, and hence if/when the FOR/NEXT loop gets executed.  Normally, FOR/NEXT in your Program or Task code block will ALWAYS execute (there is no "power flow" enable on a FOR/NEXT loop, other than having the FOR count be 0 or less), but there is an ENABLE leg on a CALL subroutine box!