On Fri, 18 Apr 2014 00:05:03 -0400, Kagamin s...@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
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.
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.
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
On Fri, 18 Apr 2014 12:59:35 -0400, Kagamin s...@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
On Thursday, 17 April 2014 at 00:55:19 UTC, Dicebot wrote:
Just in case, the key line to pay attention to in that example
is this one:
CellIndex[0] c_;
It is a commonly used C idiom for dynamically sized structures
that D also supports.
Absolutely. However, from a technical point of view,
Dicebot:
Just in case, the key line to pay attention to in that example
is this one:
CellIndex[0] c_;
When you define dynamically sized structs it's also a good idea
to wrap the items access with some kind of get/set functions, to
make the code less bug-prone (and sometimes there is also
Bound checked version of variable size struct:
http://dpaste.dzfl.pl/fcd91d6912d3
On Thursday, 17 April 2014 at 17:15:15 UTC, Kagamin wrote:
Bound checked version of variable size struct:
http://dpaste.dzfl.pl/fcd91d6912d3
Well, indexes getter could take cellCount into account...
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
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.
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.
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,
State* pointer in sokoban example is a perfect 1 indirection.
On Thursday, 17 April 2014 at 18:17:59 UTC, Kagamin wrote:
State* pointer in sokoban example is a perfect 1 indirection.
It is not related to actual dynamic struct thing, which is why
I have highlighted the line to look at. Minimal example is this:
struct Dynamic
{
size_t length;
How is this different from my example?
On Thursday, 17 April 2014 at 18:29:21 UTC, Kagamin wrote:
How is this different from my example?
b = new byte[StateImpl.sizeof + CellIndex.sizeof*cellCount];
this line creates heap indirection
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.
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
On Thursday, 17 April 2014 at 18:40:27 UTC, Kagamin wrote:
And how heap indirection is different from stack indirection?
It's still indirection.
Locality. The stack is (within reason) readily available in cache.
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
On Thu, 17 Apr 2014 14:40:25 -0400, Kagamin s...@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
Well, it's proof of concept of bound checked variable-size
struct, I wrote it in a minute. It even compiles and runs.
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
Is it possible to have a structure with a dynamic size? The
structure would contain an array.
I know I can use templates, but the size won't be known at
compile time. I also know I could just put a dynamic array into
it, but that way it would just be a pointer.
I know there would be major
On Wed, 16 Apr 2014 23:15:40 +, Jeroen Bollen wrote:
Is it possible to have a structure with a dynamic size? The structure
would contain an array.
I know I can use templates, but the size won't be known at compile time.
I also know I could just put a dynamic array into it, but that way
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
But that code requires a very updated compiler. Otherwise you
will need a little different code.
Bye,
bearophile
On Wednesday, 16 April 2014 at 23:15:43 UTC, Jeroen Bollen wrote:
Is it possible to have a structure with a dynamic size? The
structure would contain an array.
I know I can use templates, but the size won't be known at
compile time. I also know I could just put a dynamic array into
it, but
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
But that code requires a very updated compiler. Otherwise you
29 matches
Mail list logo