Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: Bolt on June 06, 2023, 01:17:45 PM

Title: Block Copy Nested Structure Fields
Post by: Bolt 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?
Title: Re: Block Copy Nested Structure Fields
Post by: franji1 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).
Title: Re: Block Copy Nested Structure Fields
Post by: franji1 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)
Title: Re: Block Copy Nested Structure Fields
Post by: Bolt 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.
Title: Re: Block Copy Nested Structure Fields
Post by: franji1 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!