[fpc-pascal] fpc has trouble with array types

Andrew Pennebaker andrew.pennebaker at gmail.com
Tue Oct 18 19:52:52 CEST 2011


RRUZ<http://stackoverflow.com/questions/7802319/whats-the-syntax-for-literal-arrays-in-free-pascal>has
the answer:

const
 XLAT_SIZE = 53;
 xlat : Array[0..XLAT_SIZE-1] of Integer = (
 $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
);

Works for me!

Cheers,

Andrew Pennebaker
www.yellosoft.us

On Tue, Oct 18, 2011 at 5:36 AM, Sven Barth <pascaldragon at googlemail.com>wrote:

> Am 18.10.2011 11:33, schrieb Sven Barth:
>
>  Am 18.10.2011 11:19, schrieb Vincent Snijders:
>>
>>> 2011/10/18 Sven Barth<pascaldragon at googlemail.**com<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).
>>>
>>
>> Could be that I missed the reference counting of arrays. At least I
>> always try to "free" my arrays by hand ^^
>>
>
> Yes, seems like I missed the ref counting. See http://www.freepascal.org/*
> *docs-html/ref/refsu15.html#**x39-430003.3.1<http://www.freepascal.org/docs-html/ref/refsu15.html#x39-430003.3.1>
>
> ====
> As remarked earlier, dynamic arrays are reference counted: if in one of the
> previous examples A goes out of scope and B does not, then the array is not
> yet disposed of: the reference count of A (and B) is decreased with 1. As
> soon as the reference count reaches zero the memory, allocated for the
> contents of the array, is disposed of.
> ====
>
>
> Regards,
> Sven
> ______________________________**_________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.**org<fpc-pascal at lists.freepascal.org>
> http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20111018/b3cb6ed8/attachment.html>


More information about the fpc-pascal mailing list