Re: void initialization vs alignment holes

2010-03-07 Thread bearophile
strtr: > static if( S.sizeof == members.sizeof ) > S s = void; > else > S s; You can use something like this :-) import std.stdio: writeln; int unusedBytesStruct(S)() if (is(S == struct)) { int totUsed; foreach (field; S.init.tupleof) totUsed += field.sizeof; return cast(in

Re: void initialization vs alignment holes

2010-03-07 Thread bearophile
The situation is ugly, see the post in the main newsgroup: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=107153 Bye, bearophile

Re: void initialization vs alignment holes

2010-03-07 Thread bearophile
strtr: >Might this be worth an explicit mention on digitalmars?< Currently the documentation has some semantic holes that must be filled :-) > Suppose I'd still would like to use void optimizations, how do you clear the > holes manually? If you need to fill the holes manually, then probably it

Re: void initialization vs alignment holes

2010-03-06 Thread strtr
BCS Wrote: > IIRC zero filling a block is likely cheaper that zero filling holes in it. > I'd avoid "=void" unless you know you will be copying structs into the space > (that will copy the holes as well). And unless you will never compare the struct, as the garbage bits will also be compared. I

Re: void initialization vs alignment holes

2010-03-06 Thread BCS
Hello Strtr, Suppose I'd still would like to use void optimizations, how do you clear the holes manually? IIRC zero filling a block is likely cheaper that zero filling holes in it. I'd avoid "=void" unless you know you will be copying structs into the space (that will copy the holes as well

Re: void initialization vs alignment holes

2010-03-06 Thread strtr
bearophile Wrote: > strtr: > > > I suspect this isn't the case for void initialization; if my struct has > > some alignment hole I better not void initialize it if ever I want to > > compare it with something. > > Is this correct? > > That has to be correct. Might this be worth an explicit men

Re: void initialization vs alignment holes

2010-03-06 Thread BCS
Hello Strtr, BCS Wrote: Hello Strtr, Would you ever have an alignment hole if all the struct contains are basic types(excluding bool)? real, char[n], byte[n] and short[m] (for n%4 != 0 and m%2 != 0) might be an issue. Sounds logical, thanks! I don't actually *know* those will be a pro

Re: void initialization vs alignment holes

2010-03-06 Thread strtr
BCS Wrote: > Hello Strtr, > > > Would you ever have an alignment hole if all the struct contains are > > basic types(excluding bool)? > > real, char[n], byte[n] and short[m] (for n%4 != 0 and m%2 != 0) might be > an issue. > Sounds logical, thanks!

Re: void initialization vs alignment holes

2010-03-06 Thread BCS
Hello Strtr, Would you ever have an alignment hole if all the struct contains are basic types(excluding bool)? real, char[n], byte[n] and short[m] (for n%4 != 0 and m%2 != 0) might be an issue. -- ... <

Re: void initialization vs alignment holes

2010-03-06 Thread bearophile
strtr: > I suspect this isn't the case for void initialization; if my struct has some > alignment hole I better not void initialize it if ever I want to compare it > with somthing. > Is this correct? That has to be correct. > Would you ever have an alignment hole if all the struct contains ar

void initialization vs alignment holes

2010-03-06 Thread strtr
This is probably going a bit above my head, but "the existence of alignment holes in the objects is accounted for, usually by setting them all to 0 upon initialization" I suspect this isn't the case for void initialization; if my struct has some alignment hole I better not void initialize it if