On 6/27/15 3:24 PM, Walter Bright wrote:
On 6/26/2015 7:45 PM, Parke via Digitalmars-d wrote:
Or, perhaps more precisely: Does the caller of toString need to know
the size of the struct that toString will return?
Yes.
In the above example, buf's length is uint.sizeof * 3. But what if
buf's length was a function of u (and therefore only known at
run-time), rather than a function of uint.sizeof?
In cases where the size cannot be known in advance, the returned struct
can malloc/free the extra space.
Be careful with this. You need a reference counted type to do this
properly (or make the result not copyable).
Also, malloced data is not scanned for pointers by the GC.
-Steve