tags:

views:

213

answers:

4

Hello,

For example,We have a DWORD = $12345678

Which of the instructions would be faster - absolute or Move()?

var a:DWORD = $12345678;
    b:Array[0..3] of byte absolute a;


var a:DWORD = $12345678;b:Array[0..3] of Byte
begin
  Move(a,b,4);
end;

Specifically,I'm asking what exactly 'absolute' does,because if it doesn't use additional memory to write that byteArray then I have no reason to use Move instead of absolute in that case so how does 'absolute' work?

+7  A: 

The 'absolute' directive points to the same memory as the specified variable. No code is executed, so yes it is faster than Move or any other code.

TOndrej
+16  A: 

absolute does not perform any operation; it declares the address of a var to be the same as another var.

Move() performs a copy operation, which takes some time.

With absolute, both vars are stored at the same address, your second declaration stores the vars at different locations.

devio
+5  A: 

'Absolute' is just another form of type-casting as if you got a location reference to your 'A' DWORD with a PByte pointer to work with the bytes as: PByte(@A)^[0] := 3, PByte(@A)^[1] := 4 etc. You're poking (or reading) the DWORD variable just in another way. Pascal is a strongly-typed language but with type-casting (or ABSOLUTE) you can do pretty much anything. Bri

Brian Frost
+1  A: 

how does 'absolute' work?

See Absolute (for) beginners

Alexander