I made a bit of a big post with "Future development plans" where I
mentioned 'aligned allocation', especially since C11 has the feature and
Microsoft have their own non-portable set of functions. Hopefully it
will spawn some discussion.
Sorry to keep going back to the dynamic array issue. The comparison
with static arrays is a good one, because this is where bugs often appear.
Take the common Move function for some array V (assume it's an array of
Integers for the sake of this example) and a pointer to a block of memory:
Move(V, DestPtr^, Length(V) * SizeOf(Integer)); { V and DestPtr can be
swapped around if you like }
If V is a static array, this will work as expected, since V points to
the first element in the array. However, if V is a dynamic array, then
this call will likely raise an access violation, or if it doesn't,
DestPtr^ will contain garbage - if you're writing to V, you'll end up
giving it an invalid pointer to its data, while the real pointer will
end up dangling. You have to specify V[0] rather than V for it to work
as expected (which works for static arrays too).
Gareth aka. Kit
On 21/04/2020 16:18, Sven Barth wrote:
denisgolovan <denisgolo...@yandex.ru <mailto:denisgolo...@yandex.ru>>
schrieb am Di., 21. Apr. 2020, 14:58:
> I think Gareth meant the address of V instead (Pointer(@V)).
>
> Regards,
> Sven
Hm. I have no idea why anyone would take pointer to pointer :)
Because they might have forgotten that dynamic arrays behave different
from static ones?
BTW, Sven, what's your opinion on dynamic arrays alignment problem?
I have none, cause I'm not dealing with such problems.
Regards,
Sven
--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
_______________________________________________
fpc-devel maillist - fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel