What it the preferred method to write a class to a file?

Regan Heath regan at netwin.co.nz
Mon Jul 24 19:07:40 PDT 2006


On Mon, 24 Jul 2006 20:15:03 -0400, Jarrett Billingsley  
<kb3ctd2 at yahoo.com> wrote:
> "Regan Heath" <regan at netwin.co.nz> wrote in message
> news:optc56yyzv23k2f5 at nrage...
>
>> Option #1
>> Note: .dup is required the local 'i' becomes invalid after the function
>> returns
>> char[] uint_to_char(uint i)
>> {
>> char[] str = new char[4];
>> *cast(uint*)str.ptr = i;
>> return str.dup;
>> }
>
> I don't think a .dup is required here; when you write  
> "*cast(uint*)str.ptr =
> i", it's copying the data from i to the array's memory, not setting the
> array's pointer to point to the integer.

Oops, you're right.

> Option 2 is actually semantically
> the same.  Would be kind of interesting to see what machine code each
> version produces :)

Regan



More information about the Digitalmars-d-learn mailing list