Jarrett Billingsley jarrett.billingsley at
Fri Oct 10 05:37:13 PDT 2008

On Fri, Oct 10, 2008 at 4:42 AM, Hendrik Renken <funsheep at> wrote:

> let me modify your example:
>> STRUCT foo(byte[] myData)
>> {
>>     STRUCT s = STRUCT(myData);
>       return s;
>> }
> will the content of s now be copied when it is returned?

Yes, the contents of *s* will be copied (that is, the array
reference), but *not* the array data itself.

>> Your example should probably look like this, as there's no point in heap
>> allocating small structs:
> what means small? below how many bytes?

It's subjective, but a struct that's only 4-8 bytes can be easily
passed around in registers and there is therefore no need to
heap-allocate it.  Of course on a 64-bit platform even a 16-byte
struct is small.

More information about the Digitalmars-d-learn mailing list