[fpc-devel] static vs dynamic arrays

Jonas Maebe jonas.maebe at elis.ugent.be
Tue Apr 4 16:28:04 CEST 2006

On 4 apr 2006, at 15:01, Michael Van Canneyt wrote:

>> Thank you, that was informative. Here are the results (one program  
>> at the end for completeness):
>>            ap^:=app^; inc(ap); dec(bp);
>> 4780    4845
>>            ap^:=1; inc(ap);
>> 3703    3703
>>            ap^:=a[0] xor ap^; inc(ap);
>> 3813    4203
>> Now the question rises again in the original form (not very  
>> correct, see previous messages):
> Because of the copy-on-write mechanism.

No, that is not true. He's now using plain pointers. The compiler  
does not keep track of the fact that a particular pointer points to a  
reference-counted type. Both loops are now equally fast in principle  
(and they are in practice on e.g. ppc).

The only "problem" is that c and c1 are also assigned registers, and  
become in use after the first loop. Because of this, bp and bpp can't  
be assigned a register anymore on x86 and are kept in memory instead  
of in a register. The register allocator puts registers with most  
conflicts in memory first, and these variables apparently have more  
conflicts than c/c1.

The used register allocation algorithm is not optimal (there are no  
known optimal algorithms, except for exhaustive ones), but it  
performs well in general. Everyone is free to attempt to optimize it  
further, as long as it doesn't break (i.e., it must give a valid  
result in all cases, and not spend an hour on compiling the compiler).


More information about the fpc-devel mailing list