Question about Walter's Memory DisAllocation pattern

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Sat Jun 27 12:24:35 PDT 2015


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.



More information about the Digitalmars-d mailing list