The way that I have it shifts everything to the left automatically when you put data into MyArray - by putting MyArray2 back to originating array it will be shifted one to the left.
Announcement
Collapse
No announcement yet.
Shift an array to the left
Collapse
X
-
Code:Dcl-C Arrsze const(100); Dcl-C Arrsze2 const(99); Dcl-s MyArray Char(32) dim(Arrsze); Dcl-S MyArray2 Char(32) Dim(Arrsze2) based(MyArray2_Ptr); Dcl-s Myarray2_Ptr Pointer Inz(%Addr(MyArray(2))); Dcl-s Orig Char(32) Dim(100); Dcl-S i Int(3); ... For i = 1 to %Elem(MyArray); Orig(i) = %Char(i); Endfor; MyArray = Orig; Orig = MyArray2; MyArray(100) = ' '; *INLR = *On;
Comment
-
Thanks again for all the good ideas, everybody. For now I'm going with J. Taylor's code.
Code:MyArray1 = %subarr(MyArray :2); MyArray = MyArray1;
Comment
-
FWIW, that's is (conceptually, anyway) what memmove() does under the covers, it moves to a temporary area, then moves to the destination -- just like the code that Ted settled on. I guess depending on the implementation, memmove() could potentially run faster (or %subarr might, not sure -- you'd have to benchmark to know) but unless the performance turned out to be a problem, I'd keep the %subarr version since it'll be much easier for the next programmer to understand/maintain.
I can't imagine the difference would be big.
Comment
-
You can also do the following:
Code:Dcl-DS Array_DS; MyArray Char(32) Dim(100); MyArray2 Char(32) Dim(100) Pos(33); END-DS Array_DS;
Code:MyArray = MyArray2;
Comment
-
Originally posted by jollyegeorge View PostSorry to add in this Post, I am not able to do a new post -
Perhaps make another attempt to create a new post. When it works, you're more likely to be seen by the many helpful people here.
Comment
-
I don't know how memmove() works under the covers, whether it creates its own copy or whether it's clever enough to handle the overlap without a temp.
Ted, you could do a benchmark to see if memmove() significantly beats using the temp array. If so, I'd use memmove() with some heavy comments to explain what's happening. If it's not significantly better, I'd use the temp array, since as Scott says, it's a bit more obvious what's going on.
Ted, I award you a Gold Star for reading the documentation! Well, I couldn't see a gold star emoji, so I'm awarding you a lleaping llama.
- Likes 1
Comment
-
Thanks, Barbara, but this is an old thread. I don't even remember what I was working on at the time, who I was doing the project for, or why speed was so important. Jolly E. George tacked a new message onto this thread because the forum would not allow him to start a new topic. No one has answered his question, including me. (Haven't had time to look at it.)
Life on this planet is full of weird happenings.
Comment
-
Originally posted by jollyegeorge View PostI am calling a RPG module, which is returning a array as result, now i need to accept that array in my S.so in the INOUT parameters
i need to code an array
What do you mean by "i need to accept that array in my S"? Looks like there's a word missing there. Perhaps its a stored procedure, since you mention INOUT, and I know that syntax is used in stored procedures. But, I don't know anything more than that... is it an external stored procedure? What language is it written in? How are you calling it?
More technical details would be very helpful here. If possible, post an example of the code.
Comment
Comment