[fpc-devel] Faster InitObject

Hans-Peter Diettrich DrDiettrich1 at aol.com
Thu Feb 23 23:20:35 CET 2012

Amir schrieb:

> The performance of FillChar is not my problem, The main issue in my case 
> is that my class has a big array defined inside it. I developed my code 
> such that this array does not need to be initialized with zero initially 
> (I have not assumed anything about the content of this array).
> But the InitInstance function, initialize the array with zero.
> I can see a simple solution to resolve my problem. I can change the 
> array, in my class, to a dynamic array or pointer or ...
> But what if I had, let's say, many variables inside my class? Or a big 
> data structure?

The initialization of every class instance is a major improvement over 
e.g. C++ classes. I'd say that you should accept it, instead of 
searching for workarounds, with hard to predict effects in the remaining 

While it may be possible to move elements, which do not deserve an 
initialization, out of the instance, this solution adds time to *every* 
later usage, and may require methods (calls!) to address these values as 

Another solution could move all uninitialized members to the end of the 
instance, and to initialize only the first part of the instance. But 
such modified behaviour will also affect all derived classes, whose 
added members then either stay uninitialized (what's unexpected), or 
will revert your optimization of the base class.


More information about the fpc-devel mailing list