Delphi Initialize Record

Posted on admin
Delphi Initialize Record 9,2/10 5778 votes

This part of the RTL is not optimzed. IMHO record initialization should not be made at runtime, using RTTI, but should be prepared at compile time, with proper code generation. An heuristic algorithm should let the compiler switch between two ways of implementation: – if the record contain a lot of non reference-counted data and a few reference-counted fields, generate code to initialize only some reference-counted field; – if the record contain mainly reference-counted data (as in your benchmark), generate code to make a fillchar of 0 on the whole record (like for class initialization).

Using the With keyword, the fields of a record can be addressed without the need to prefix each with the record name. Unlike Object Oriented languages like Java, the Delphi Record type provides a better performing mechanism for passing similar groups of data than data classes. Is it safe to use Default() assignment to initialize record variables in Delphi? Tag: delphi Assigning Default(TMyRecord) to a variable of TMyRecord is said to internally call first Finalize and then zero out the memory like FillChar would.

You did only benchmark initialization. But finalization also uses the RTL and RTTI – so can be pretty slow. And this finalization code is shared with the class release code. IMHO finalization should also not be made at runtime using RTTI, but at compile time, with code generation.

For our enhanced RTL (only for Delphi 7 and 2007), we re-wrote the initialization/finalization part of the RTL with optimized asm, with some success. See and But compile-time code generation should be much better.

I think that PTest should be with try/finally (similar as ‘compiler magic’ will do, because it’s mem-leak ‘safe’) if you want compare with same functionality: procedure PTest(AI: IInterface); var PR: TPRec; begin PR.PP:= nil; // custom initialization try IInterface(PR.PP):= AI; finally IInterface(PR.PP):= nil; // custom finalization; end; end; It’s still slower (on my machine about 4-5%) because of InitializeRecord/FinializeRecord when using ITest. If you look for perf.

Currently It supports 55 formats of video downloads. Now you can download songs, movies, episodes, trailers, clips or any Youtube video without visitng the Youtube site with hassle free controls and beautiful responsive UI. Sudu mathu dinaka mp3 download.

Delphi

Delphi Initialize Record Array

You can use ‘const interface’, so there won’t be AddRef/Release on each call (similar with other ref-counted types, like Strings or dyn-arrays): procedure ITest(const AI: IInterface); 85% faster than ITest(const AI: IInterface).