[fpc-devel] Faster InitObject
Tommi Prami
groups.tprami at gmail.com
Thu Feb 23 10:05:10 CET 2012
>
>
> > Incl. Self. Called Function
> > 29.78 29.72 26M SYSTEM_FILLCHAR$formal$INT64$BYTE
> > 19.07 19.07 123M SYSTEM_MOVE$formal$formal$INT64
> > 3.63 3.63 70M SYSTEM_SYSGETMEM_FIXED$QWORD$$POINTER
> > ....
> >
> > The main caller of FillChar function is
> > system_TObject_$__NewInstance$$TObject which called Fillchar 26 Million
> > times.
> >
> > NewInstance method in TObject calls InitInstance which is an inline
> > function and defined as follows:
> >
> > class function TObject.InitInstance(instance : pointer) :
> > tobject; {$ifdef SYSTEMINLINE} inline; {$ENDIF}
> >
> > begin
> > { the size is saved at offset 0 }
> > fillchar(instance^, InstanceSize, 0);
> > { insert VMT pointer into the new created memory area }
> > { (in class methods self contains the VMT!) }
> > ppointer(instance)^:=pointer(self);
> > if PVmt(self)^.vIntfTable <> @emptyintf then
> > InitInterfacePointers(self,instance);
> > InitInstance:=TObject(Instance);
> > end;
> >
> > My question is do we need to call fillchar in InitInstance? Or Is there
> > any way to avoid calling InitInstance?
>
> Yes, FillChar is needed, because a class instance is guaranteed to
> have Bennett initialized with zero before the first constructor is
> called (this way the fields are basically initialized by 0, Nil or ''
> depending on the field type).
>
>
But still...
Any improvement done in the Creating and Freeing an Objects would be
welcome :)
We need the FillChar there, but if the object creation could be
optimized even a little bit, it would benefit almost all the code. Some
more than others... But still...
-Tee-
More information about the fpc-devel
mailing list