April 17, 2014
Well, cache locality can be optimized without reducing number of indirections, as long as the data is likely to be in cache.
I agree with bearophile that variable size structs reduce number of indirections and have no direct relation to cache locality. One may have no time or no desire to initialize all the pointers or no place to put them.
April 17, 2014
On Thu, 17 Apr 2014 14:40:25 -0400, Kagamin <spam@here.lot> wrote:

> So you assert that variable length structs can't be allocated on heap and sokoban example is a wrong example of variable length struct usage?
>
> And how heap indirection is different from stack indirection? It's still indirection.

I think the biggest issue I would have with your implementation would be if I wrapped it in another struct that I wanted to store on the heap.

-Steve
April 18, 2014
Well, it's proof of concept of bound checked variable-size struct, I wrote it in a minute. It even compiles and runs.
April 18, 2014
On Wednesday, 16 April 2014 at 23:36:05 UTC, bearophile wrote:
> Jeroen Bollen:
>
>> Is it possible to have a structure with a dynamic size?
>
> See an usage example I have written here:
> http://rosettacode.org/wiki/Sokoban#Faster_Version

This can illustrate
1. fairly straightforward translation of true C code to better C (bound checked D); such translation is important if one doesn't want to deeply refactor the debugged algorithm, but still reasonably gets bound checked code.
2. how easy is it to write such bound checked code.
3. developer doesn't need to design both safe and unsafe versions (as in C and C++, it can give better control of optimization, but is counterproductive, when you want to turn off safety globally), he writes safe code and gets unsafe one for free - with a compiler switch, and sees for himself, how big is performance trade-off - effortlessly, no work was spent on unsafe version, which can be another advertisement for D.
April 18, 2014
On Fri, 18 Apr 2014 00:05:03 -0400, Kagamin <spam@here.lot> wrote:

> Well, it's proof of concept of bound checked variable-size struct, I wrote it in a minute. It even compiles and runs.

Please take no offense :) I just was pointing out a difference between a hand-managed and hand-written struct that I might have written and the one that you created. Depending on usage, yours might be sufficient.

Note, you could probably, with mixin magic, make a version that could be emplaced inside a struct or class without an extra indirection.

-Steve
April 18, 2014
I mean, it doesn't cover all scenarios, but can be extended to support them. The indexes array does just that: it's emplaced without indirection, but still is bound checked.
April 18, 2014
Oh, and I don't believe, that a variable-size struct can be emplaced inside fixed-size struct or class. Only as a smart pointer from the example.
April 18, 2014
On Friday, 18 April 2014 at 13:10:28 UTC, Steven Schveighoffer wrote:
> Note, you could probably, with mixin magic, make a version that could be emplaced inside a struct or class without an extra indirection.

Speaking about mixin magic, you probably suggest to do it overly generically, though it seems, use cases for variable size structs are specialized, specialized code and specialized data structures, so I suspect specialized approach will be more productive, intuitive, understandable, simple and straightforward for such tasks, generic approach is probably inadequate here. But if you can do it, you can try.
April 18, 2014
On Fri, 18 Apr 2014 12:59:35 -0400, Kagamin <spam@here.lot> wrote:

> Oh, and I don't believe, that a variable-size struct can be emplaced inside fixed-size struct or class. Only as a smart pointer from the example.

It goes at the end. Then you need to allocate the whole thing with that in mind.

-Steve
1 2 3
Next ›   Last »