Replacing C's memcpy with a D implementation

Steven Schveighoffer schveiguy at yahoo.com
Mon Jun 11 13:00:10 UTC 2018


On 6/11/18 4:00 AM, Walter Bright wrote:

> (I notice it is doing __doPostblit(). This looks wrong, D allows data to 
> be moved. As far as I can tell with a perfunctory examination, that's 
> the only "can throw" bit.)

No, __doPostblit is necessary -- you are making a copy.

example:

File[] fs = new File[5];

fs[0] = ...; // initialize fs
auto fs2 = fs;
fs.length = 100;

At this point, fs points at a separate block from fs2. If you did not do 
postblit on this, then when one of those arrays is destroyed, the other 
will become invalid, as the File reference count would go to 0.

-Steve


More information about the Digitalmars-d mailing list