[fpc-pascal] dynamic array contents and system.move

J├╝rgen Hestermann juergen.hestermann at gmx.de
Sun Apr 25 17:53:04 CEST 2010


>>> Simply because dereferencing a dyn. arrays makes no sense because
>>> it is more than just a simply data collection.
>> Realy? What else is happening in the background?
> Reference counting (also of the stored data), automatic length storage.

But that has nothing to do with the fact that the identifier "MyArray" should have the same address as "MyArray[0]" so that both should be usable for move or fillchar. The first means the whole array while the latter means the first element only.
 
>> So what is the difference between 'MyArray[0]' and 'MyArray^'? 
> MyArray[0] enforces range checking if it is enabled, further
> differences, see below.

Still this is not relevant when using MyArray^ instead of MyArray[0]. Both should mean the same address (and that's the only thing that move/fillchar need). In case the used pointer is nil a runtime error could occur when trying to dereference it (as is done for other pointers too).

>> Don't they mean the same address? 
> I would expect to get @MyArray[0]-sizeof(pointer)*2 when doing MyArray^
> (which is not allowed), because this is the start of the actual array
> information.

I don't. I think it is the same as for AnsiStrings: The pointer points to the first element and the reference counter is stored at lower addresses. So you should be able to move x bytes from the beginning of MyArray without the need to know the first element number. 

The identifier of a dynamic array should either be a pointer (so that it has to be dereferenced with ^ when accessing elements) or it should mean the beginning of the array (starting with the first element) *in all cases* (not only in some as it's now). 



More information about the fpc-pascal mailing list