[fpc-pascal] TFileStream.WriteBuffer() and RAM used ?

Michael Van Canneyt michael at freepascal.org
Fri Dec 9 13:26:37 CET 2016



On Fri, 9 Dec 2016, fredvs wrote:

> Hello.
>
> Thanks Michael for answer.
>
>> What happens with the buffer in which you had data, this we do not know.
>
> Here is the schema of recording:
>
> 1) At creation:
> DataRec := TMemoryStream.Create;
>
>
> 2 ) In loop:
> ...
> DataRec.WriteBuffer(InputBuffer[0], Length(InputBuffer)); // RAM used
> increase at each loop

The RAM increase is normal...

> ...
>
> 3) At end of recording:
>
> function WriteWave(FileName: ansistring; aDataRec: TMemoryStream): word;
> var
> ...
>  f: TFileStream;
> ...
> begin
>    f := TFileStream.Create(FileName, fmCreate);
>    ...
>    f.WriteBuffer(ID, 4);  // add some stuff for wav header.
>    ...
>    f.CopyFrom(aDataRec.Data, aDataRec.Data.Size);
>   ...
>   f.free;


And where do you free DataRec ?

>
> The buffer (InputBuffer) used to get the samples from input device is
> re-filed at each loop.
> The data of  (InputBuffer) are added to the other buffer (DataRec) used for
> WriteWave() (procedure at end of recording) in each loop.

The increase in RAM is normal, since you store the input in memory before writing it to disc.

Make sure you free the datarec after writing to file.

Michael.



More information about the fpc-pascal mailing list