On 11.05.2011 20:50, Graeme Geldenhuys wrote:
On 11 May 2011 14:35, Sven Barth<pascaldragon@goo*****> wrote:
function SortComponentsForName(Item1, Item2: Pointer): Integer;
var
Comp1, Comp2: TComponent;
begin
Comp1 := TComponent(Item1);
Comp2 := TComponent(Item2);
This is what I have always been using.... Is one method more efficient
(generated code) than the other?
The "absolute" version needs (in the example) 2 * SizeOf(Pointer) less
stack space and also the two assignments aren't needed.
Example:
===source begin===
procedure Test1(aParam1, aParam2: Pointer);
var
param1: TObject absolute aParam1;
param2: TObject absolute aParam2;
begin
end;
procedure Test2(aParam1, aParam2: Pointer);
var
param1: TObject;
param2: TObject;
begin
param1 := TObject(aParam1);
param2 := TObject(aParam2);
end;
===source end===
The following code is generated on i386:
===assembler begin===
.section .text
.balign 16,0x90
.globl P$ABSOLUTETEST_TEST1$POINTER$POINTER
.type P$ABSOLUTETEST_TEST1$POINTER$POINTER,@function
P$ABSOLUTETEST_TEST1$POINTER$POINTER:
.Lc1:
# Temps allocated between ebp-8 and ebp-8
# [absolutetest.pas]
# [9] begin
pushl %ebp
.Lc3:
.Lc4:
movl %esp,%ebp
.Lc5:
subl $8,%esp
# Var aParam1 located at ebp-4
# Var aParam2 located at ebp-8
movl %eax,-4(%ebp)
movl %edx,-8(%ebp)
# [10] end;
leave
ret
.Lc2:
.Le0:
.size P$ABSOLUTETEST_TEST1$POINTER$POINTER, .Le0 -
P$ABSOLUTETEST_TEST1$POINTER$POINTER
.section .text
.balign 16,0x90
.globl P$ABSOLUTETEST_TEST2$POINTER$POINTER
.type P$ABSOLUTETEST_TEST2$POINTER$POINTER,@function
P$ABSOLUTETEST_TEST2$POINTER$POINTER:
.Lc6:
# Temps allocated between ebp-16 and ebp-16
# [16] begin
pushl %ebp
.Lc8:
.Lc9:
movl %esp,%ebp
.Lc10:
subl $16,%esp
# Var aParam1 located at ebp-4
# Var aParam2 located at ebp-8
# Var param1 located at ebp-12
# Var param2 located at ebp-16
movl %eax,-4(%ebp)
movl %edx,-8(%ebp)
# [17] param1 := TObject(aParam1);
movl -4(%ebp),%eax
movl %eax,-12(%ebp)
# [18] param2 := TObject(aParam2);
movl -8(%ebp),%eax
movl %eax,-16(%ebp)
# [19] end;
leave
ret
.Lc7:
.Le1:
.size P$ABSOLUTETEST_TEST2$POINTER$POINTER, .Le1 -
P$ABSOLUTETEST_TEST2$POINTER$POINTER
===assembler end===
Regards,
Sven
--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus