<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>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.</p>
<p>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.</p>
<p>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:<br>
</p>
<p>Move(V, DestPtr^, Length(V) * SizeOf(Integer)); { V and DestPtr
can be swapped around if you like }<br>
</p>
<p>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).</p>
<p>Gareth aka. Kit</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 21/04/2020 16:18, Sven Barth wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAFMUeB9ewu+mfGp8-JWSKr8Kr4foe9sfogMx=dox03VrXBXvmQ@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="auto">
<div>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">denisgolovan <<a
href="mailto:denisgolovan@yandex.ru"
moz-do-not-send="true">denisgolovan@yandex.ru</a>>
schrieb am Di., 21. Apr. 2020, 14:58:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">> I
think Gareth meant the address of V instead (Pointer(@V)).<br>
> <br>
> Regards,<br>
> Sven<br>
<br>
Hm. I have no idea why anyone would take pointer to
pointer :)<br>
</blockquote>
</div>
</div>
<div dir="auto"><br>
</div>
<div dir="auto">Because they might have forgotten that dynamic
arrays behave different from static ones? </div>
<div dir="auto"><br>
</div>
<div dir="auto">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
BTW, Sven, what's your opinion on dynamic arrays alignment
problem?<br>
</blockquote>
</div>
</div>
<div dir="auto"><br>
</div>
<div dir="auto">I have none, cause I'm not dealing with such
problems. </div>
<div dir="auto"><br>
</div>
<div dir="auto">Regards, </div>
<div dir="auto">Sven </div>
</div>
</blockquote>
<div id="DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br />
<table style="border-top: 1px solid #D3D4DE;">
<tr>
<td style="width: 55px; padding-top: 13px;"><a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank"><img src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif" alt="" width="46" height="29" style="width: 46px; height: 29px;" /></a></td>
<td style="width: 470px; padding-top: 12px; color: #41424e; font-size: 13px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;">Virus-free. <a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank" style="color: #4453ea;">www.avast.com</a>
</td>
</tr>
</table><a href="#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"> </a></div></body>
</html>