<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">denisgolovan via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> schrieb am Mi., 2. Juni 2021, 13:28:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
> Well as already discovered type like strings can not go into a "record case"<br>
> <br>
> But... The above record is anyway of constant size. I.e. the memory for<br>
> the field is always included, even if it is not used.<br>
> <br>
> Since the "false" block is empty, you can do<br>
> <br>
> type<br>
> generic TOption<T> = record<br>
> IsSome:boolean;<br>
> some: T;<br>
> end;<br>
> <br>
> It is not as expressive to the reader of the code. But it leads to the<br>
> same data in memory.<br>
<br>
Yes. <br>
Except that "some" is still initialized with something (some default) and dropped and copied and assigned despite conceptually being empty.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">That would have to be the case otherwise as well. And even worse: the RTL would need to decide at runtime if it would need to manage that entry.</div><div dir="auto">With the suggested solution (which is essentially what TNullable<> provides as well) this will be rather cheap if the element is Nil (aka empty) anyway. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </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">
</blockquote></div></div></div>