Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-03

unit system;  procedure move();

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

Hi

I need more informations about the move() procedure  form unit system. I want to shift an array (values:array[0..Maximum-1] of single) like the following lines:

for i:=Maximum-1 downto 1 do values[i]:=values[i-1];
values[0]:=sameothervalue;

I found the move procedure (unit system) and wrote this lines:

move(values[0],values[1],Maximum*sizeof(single));
values[0]:=sameothervalue;

I would use the move procedure, because the move procedure is very quickly. The program runs very well with move, but I would avoid access violations in future. That are the reasons of my questions:
Is the use of the move procedure right? The array length is Maximum-1. When I put this length on value[1], the last entry value[Maximum-1] would be deleted or would be shifted in an different memory area? What happens with the last entry value[Maximum-1]?

Thank you.

Regards,
Markus

FreePascal Mailing List:

Reply by email

Jonas Maebe
to Unknown author
Show quoted text 23 lines
I need more informations about the move() procedure form unit system. I want to shift an array (values:array[0..Maximum-1] of single) like the following lines: for i:=Maximum-1 downto 1 do values[i]:=values[i-1]; values[0]:=sameothervalue; I found the move procedure (unit system) and wrote this lines: move(values[0],values[1],Maximum*sizeof(single)); values[0]:=sameothervalue; I would use the move procedure, because the move procedure is very quickly. The program runs very well with move, but I would avoid access violations in future. That are the reasons of my questions: Is the use of the move procedure right? The array length is Maximum-1. When I put this length on value[1], the last entry value[Maximum-1] would be deleted or would be shifted in an different memory area?

It would overwrite whatever is placed in memory after the array (which, in case there is nothing, indeed causes an access violation). Use this instead:
move(values[0],values[1],(Maximum-1)*sizeof(single)); values[0]:=sameothervalue;

Jonas

Reply by email

Pete Cervasio
to Jonas Maebe
Jonas Maebe wrote 12 lines
On 17 Mar 2008, at 12:34, wrote: > Is the use of the move procedure right? The array length is > Maximum-1. When I > put this length on value[1], the last entry value[Maximum-1] would > be deleted > or would be shifted in an different memory area? It would overwrite whatever is placed in memory after the array (which, in case there is nothing, indeed causes an access violation). Use this instead: move(values[0],values[1],(Maximum-1)*sizeof(single)); values[0]:=sameothervalue;

Wouldn't it be better to use the length function on the array? Or does that not work in some compiler modes?

    move(values[0], values[1], (length(values)-1) * sizeof(single));

If the size of the array is ever changed, no code change is required.

Best regards,
Pete C.

Reply by email