[fpc-devel] Class field reordering

michael.vancanneyt at wisa.be michael.vancanneyt at wisa.be
Tue Jul 17 09:40:36 CEST 2012



On Tue, 17 Jul 2012, Martin Schreiber wrote:

> On Monday 16 July 2012 17:25:58 michael.vancanneyt at wisa.be wrote:
>> On Mon, 16 Jul 2012, Martin Schreiber wrote:
>>> On Monday 16 July 2012 16:50:06 michael.vancanneyt at wisa.be wrote:
>>>> Well, from your code adding the following to the protected section:
>>>>
>>>>    Property ValueBuffer : Pointer Read FValueBuffer;
>>>>    Property Validating : Boolean Read FValidating ;
>>>>
>>>> Should be enough to remove the need for the TFieldCracker ?
>>>
>>> Unfortunately no:
>>> "
>>> procedure tmsebufdataset.checkfreebuffer(const afield: tfield);
>>> begin
>>> {$ifdef FPC}{$warnings off}{$endif}
>>> with tfieldcracker(afield) do begin
>>> {$ifdef FPC}{$warnings on}{$endif}
>>>  if foffset and 2 <> 0 then begin
>>>   freemem(fvaluebuffer);
>>>   fvaluebuffer:= nil;
>>>  end;
>>> end;
>>> end;
>>> "
>>
>> If I understand correctly, you have in the record buffer just the pointer
>> of the (wide)string instead of the actual string data ?
>>
> Correct. The UnicodeString pointer. That has not directly to do with the
> procedure above BTW. This one is to allow changing field values in OnValidate
> IIRC.
>
>> If so, why then didn't you implement the string fields as blobs are
>> implemented in SQLDB (it is basically the same problem), in that case you
>> would not need the internal fields of TField at all ?
>>
> Maybe, but what about performance? Another complication is the "updatebuffer"
> with the "oldvalues".

Thinking about it:

I would allocate the buffer as is, with for all string fields an
integer-sized slot in the buffer. The slot contains an index, pointing 
to a separate array of strings containing  N*M*2 strings. (N=number of 
records, M= Number of string fields per record, factor 2 for old values)

Field value =  Element [Index  [+1 for old value]] in the array. 
where the [Index] is stored in the buffer.

The speed performance penalty of this system should be negligable, since you
assume all records are in memory anyway.

And: everything can be done without meddling with the internals of TField.

Michael.



More information about the fpc-devel mailing list