[fpc-pascal] Array clearing

wkitty42 at windstream.net wkitty42 at windstream.net
Sat Apr 1 22:31:14 CEST 2017


On 04/01/2017 02:33 PM, J├╝rgen Hestermann wrote:
> Am 2017-04-01 um 19:42 schrieb wkitty42 at windstream.net:
>> consider this: when using a string var and writing to a binary file...
>> you reuse the string var for each value written...
>> if you don't clear the string var between fills then the binary will
>> contain "garbage" in the unused positions of the string var...
>> you can see this "garbage" when you view the binary file in hex mode...
>> the "garbage" being older longer string data than the current string data in
> the var...
>> this var may be a global throwaway string var...
>
> This can only happen for older string types where the actual length
> can differ from the reserved memory (maximum string length).
> With managed strings, this should never be possible as it would write
> only the bytes of the current length.

some situations call for fixed length records... this same "garbage" effect will 
be seen in them...

> I also don't see how this applies to an array of integers.

it may not... the subject doesn't differentiate... it only says "array" so i 
provided an example to your query about why this clearing may be desired... i 
just happened to use an array of char that we loving know as string[255]...


-- 
  NOTE: No off-list assistance is given without prior approval.
        *Please keep mailing list traffic on the list* unless
        private contact is specifically requested and granted.



More information about the fpc-pascal mailing list