funsheep at gmx.net
Fri Oct 10 01:42:50 PDT 2008
> "data" is a dynamic array reference, so STRUCT is really just this:
> struct STRUCT
> size_t length;
> byte* ptr;
This explains everything. Thanks.
> So "data" is just a number of elements and a pointer to the first one.
> When you do "new STRUCT(myData)", you're only allocating room for that.
> There's no room for array contents allocated, just the reference.
> If you do writeln(STRUCT.sizeof); it will always say 8 on a 32-bit
> system, same goes for data.sizeof.
let me modify your example:
> STRUCT foo(byte myData)
> STRUCT s = STRUCT(myData);
will the content of s now be copied when it is returned?
> Your example should probably look like this, as there's no point in heap
> allocating small structs:
what means small? below how many bytes?
More information about the Digitalmars-d-learn