[fpc-devel] New feature announcement: constant parameters for generics

Marco van de Voort fpc at pascalprogramming.org
Mon Apr 27 00:10:44 CEST 2020


Op 2020-04-26 om 11:48 schreef Sven Barth via fpc-devel:
>
> Jeppe had provided a potential usecase on the core mailing list in 
> October '18. His example is not useable as-is, but to give you an idea:
>
>  As the compiler can inline all this, the writing of maintainable, 
> hardware agnostic frameworks for embedded controllers becomes easier.

(Actually you'd probably want to use atomic RMW operations, because 
otherwise a write from a thread or interrupt routine could be 
overwritten, even if it was not on bits that clash)

> A further example could be to determine the size of a hash table: 
> Determining that at compile time instead of runtime might allow for 
> better code. At the same time the user of that code would still be 
> able to influence it.

Yup. My Genlight sorted stringlist could also use it for tuning. To 
workaround the classic tstringlist ordered insertion limit, it uses an 
(dyn) array of small arrays to store the strings, which postpones the 
inevitable with about a magnitude 10-20.

The constant would be the size of the deeper array, now a weighted value 
1024.

Larger (e.g. 4096) means less memory overhead, faster iteration, but 
with slower (random) insertion performance, which can be perfectly fine 
if your datasource is mostly in order + few mutations.




More information about the fpc-devel mailing list