[fpc-pascal] fpc has trouble with array types

Vincent Snijders vincent.snijders at gmail.com
Tue Oct 18 11:19:37 CEST 2011


2011/10/18 Sven Barth <pascaldragon at googlemail.com>:
> Am 18.10.2011 11:12, schrieb Sven Barth:
>>
>> type
>> TByteArray = array of Byte;
>>
>> function XlatPrime(): TByteArray;
>> begin
>> XlatPrime := TByteArray.Create(
>> $64, $73, $66, $64, $3b, $6b, $66, $6f,
>> $41, $2c, $2e, $69, $79, $65, $77, $72,
>> $6b, $6c, $64, $4a, $4b, $44, $48, $53,
>> $55, $42, $73, $67, $76, $63, $61, $36,
>> $39, $38, $33, $34, $6e, $63, $78, $76,
>> $39, $38, $37, $33, $32, $35, $34, $6b,
>> $3b, $66, $67, $38, $37
>> );
>> end;
>
> Before I forget it: If you use this solution (not the const one) or you use
> "SetLength", you need to free the array using "SetLength(0)" or
> "YourArrayVariable := Nil", otherwise you'll have a memory leak. You must
> not do this if you use the const solution.

That is unexpected. Until now, SetLength was used for ansistrings and
dynamic arrays, which didn't have this requirement (unless you messed
with the internals using Move).

Vincent



More information about the fpc-pascal mailing list