Ultimate Amiga
Network Boards => AMOS Language Discussion => AMOS Factory => AMOS Professional Forum => Topic started by: Umpal on May 02, 2019, 02:20:08 PM
-
Is there a fast way to shift an array (down/up), preferible using an asm insertion? I can do it with For...Next, but need something faster. Can't find any info in the manual regarding (Amcaf doesn't seem to have one either).
-
I seem to recall a memory copy function but you're going to have to compute the start and end addresses yourself using the VarPtr function and take into account the copy direction needed.
-
If you mean moving all elements in an array up or down one position, I think that's something most programmers generally avoid. You can probably solve the problem a lot more efficiently by "redefining" where the array begins, keeping track of the starting position in a separate variable. If the starting position goes below 0 you can set it equal to N instead (where N is the size of the array) and treat 0 as the next element after N in the array. It's most efficient if you don't need that kind of wrapover though, so if possible you should look for an N and starting index that makes it unnecessary.
-
I seem to recall a memory copy function but you're going to have to compute the start and end addresses yourself using the VarPtr function and take into account the copy direction needed.
Yes, Copy :P
-
Thanks guys for your quick reply.
SamuraiCrow - Before I posted I was reading about VarPtr use in this case and I concluded same thing as you proposed. However, the reason I ruled it out gave Adrazar.
Adrazar - Keeping track of starting position and redefining it makes a lot of sense but because I use zero cell of each array it can not be applied in my case (I shift it down starting from position 1 to n but I keep the 0 cell intact at a time; I'd need to keep track of the array starting from position 1 but that would become too complicated and would lose the point of making it fast and simple). Fortunately my arrays are not big (just 25 position at most but typically around 10 [they are dynamical, thus the difference]) so I'll probably stick with For...Next solution.
Thank you both again for your interest.
-
Thanks guys for your quick reply.
SamuraiCrow - Before I posted I was reading about VarPtr use in this case and I concluded same thing as you proposed. However, the reason I ruled it out gave Adrazar.
Adrazar - Keeping track of starting position and redefining it makes a lot of sense but because I use zero cell of each array it can not be applied in my case (I shift it down starting from position 1 to n but I keep the 0 cell intact at a time; I'd need to keep track of the array starting from position 1 but that would become too complicated and would lose the point of making it fast and simple). Fortunately my arrays are not big (just 25 position at most but typically around 10 [they are dynamical, thus the difference]) so I'll probably stick with For...Next solution.
Thank you both again for your interest.
Surely it isn't a big problem to re-dimension your arrays and re-number your array subscripts?
If they exist, then they can be manipulated to suit with minimal changes and a little logic/arithmetic
If you are moving by one, then dimension +1 and start at 1 instead of 0 likewise for the max
You ask for a solution, but reject it because it sounds like too much work???
No Pain No Gain.
-
I’ve read the repeat... until Is faster than for... next. Not by a lot but every computing cycle counts.