Dynamically Sized Structs

John Colvin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Apr 17 11:45:56 PDT 2014


On Thursday, 17 April 2014 at 17:50:30 UTC, Dicebot wrote:
> On Thursday, 17 April 2014 at 17:45:22 UTC, Kagamin wrote:
>> On Thursday, 17 April 2014 at 17:35:17 UTC, bearophile wrote:
>>> Kagamin:
>>>
>>>> Bound checked version of variable size struct: 
>>>> http://dpaste.dzfl.pl/fcd91d6912d3
>>>
>>> I think you are missing one of the main points of a variable 
>>> sized struct, that is to reduce by 1 the number of 
>>> indirection levels.
>>>
>>> Bye,
>>> bearophile
>>
>> As far as I can see, my implementation has only 1 indirection 
>> level.
>
> And C-like dynamic structs have 0 indirection.

Well, technically everything on the stack is accessed through an 
indirection (RBP + offset), but there are more optimisation 
opportunities if the base and/or offset is known statically. 
Performance-wise you're gaining nothing over a static array (or 
any alloca buffer) and potentially losing something compared to 
normal stack variables / struct members.


More information about the Digitalmars-d-learn mailing list