<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body smarttemplateinserted="true">
<div id="smartTemplate4-template">Hi,<br>
<br>
<p>
<blockquote type="cite"><br>
<br>
Also assume you have a record and a hashmap that stores them.
Now you add a string to the record which turns it into a
managed one and suddenly your code will no longer work,
probably resulting in subtle bugs or memory leaks. That's
/not/ what should happen for merely adding a string. It's
already bad enough that this happens with the Pascal style I/O
we don't need to have this with base container types.<br>
<br>
For calling Free we have explicit classes. But the difference
between managed types vs. not-managed types is subtle and can
change - as mentioned above - by merely adding a field.</blockquote>
</p>
<p>That is why FreePascal should merge non-managed generic classes
that have the same size when it can.<br>
</p>
But as long as FreePascal does not do it, the user needs to do the
merging manually, with all the resulting problems. And constants
generics can be used to store the size<br>
<br>
Best,<br>
Benito </div>
<div class="moz-cite-prefix">On 27.04.20 07:46, Sven Barth wrote:<br>
</div>
<blockquote type="cite"
cite="mid:6aac92de-15cd-4d91-f685-60b086fc1806@googlemail.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<div class="moz-cite-prefix">Am 26.04.2020 um 23:42 schrieb Benito
van der Zander:<br>
</div>
<blockquote type="cite"
cite="mid:532276e0-86b8-eca0-8126-f10c839130d9@benibela.de">
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<div id="smartTemplate4-template">Hi Sven,<br>
<br>
<p> </p>
<blockquote type="cite"><br>
It's not that simple. In principle you're right that the
compiler could try to merge more implementations, but this
does not depend on the declaration of the generic, but the
use of the parameter types.<br>
</blockquote>
<p>I mostly use generics for containers, especially hashmaps.
They only stores the values and never calls specific methods
on them<br>
</p>
</div>
</blockquote>
<br>
Well, nice and well for /you/ then, but there are many more uses
for generics. And as a compiler developer I /must/ think about
these cases as well.<br>
<br>
<blockquote type="cite"
cite="mid:532276e0-86b8-eca0-8126-f10c839130d9@benibela.de">
<div id="smartTemplate4-template">
<p> </p>
<blockquote type="cite"><br>
<br>
Not to mention that your TBaseHashMap would not work with
managed types...</blockquote>
</div>
<div><br>
</div>
<div>That would need be handled separately. There are probably
also people who want a container that calls .free on TObject
descendants.<br>
</div>
</blockquote>
<br>
The user should not need to care about that, especially for
general base classes.<br>
<br>
Also assume you have a record and a hashmap that stores them. Now
you add a string to the record which turns it into a managed one
and suddenly your code will no longer work, probably resulting in
subtle bugs or memory leaks. That's /not/ what should happen for
merely adding a string. It's already bad enough that this happens
with the Pascal style I/O we don't need to have this with base
container types.<br>
<br>
For calling Free we have explicit classes. But the difference
between managed types vs. not-managed types is subtle and can
change - as mentioned above - by merely adding a field.<br>
<br>
Regards,<br>
Sven<br>
</blockquote>
</body>
</html>