Thread overview | ||||||
---|---|---|---|---|---|---|
|
February 16, 2004 arraycopy in Java --> this in D? | ||||
---|---|---|---|---|
| ||||
Java: ------------- System.arraycopy (logFonts, 0, newLogFonts, 0, nFonts); D: ------------- newLogFonts = logFonts.dup; // do I need the .dup? or newLogFonts[] = logFonts[]; TIA, BA |
February 16, 2004 Re: arraycopy in Java --> this in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brad Anderson | > newLogFonts = logFonts.dup; // do I need the .dup?
>
> or
>
> newLogFonts[] = logFonts[];
>
>
> TIA,
> BA
I don't know Java but I can explain what the difference is. dup creates a new array. A slice (including []) on the left side of an assignment copies into the existing buffer.
|
February 16, 2004 Re: arraycopy in Java --> this in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brad Anderson | Brad Anderson wrote: > Java: > ------------- > System.arraycopy (logFonts, 0, newLogFonts, 0, nFonts); > > > > D: > ------------- > newLogFonts = logFonts.dup; // do I need the .dup? If these two arrays are dynamic (declared []), I think you need the "dup" or else newLogFonts will be a reference to the same array as logFonts. > or > > newLogFonts[] = logFonts[]; This is the array copying form for static-sized arrays (declared fixed length - eg. int[4] a;) |
February 16, 2004 Re: arraycopy in Java --> this in D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brad Anderson | "Brad Anderson" <brad@sankaty.dot.com> wrote in message news:c0p5ee$31g2$1@digitaldaemon.com... | Java: | ------------- | System.arraycopy (logFonts, 0, newLogFonts, 0, nFonts); | | | | D: | ------------- | newLogFonts = logFonts.dup; // do I need the .dup? Throws away any existing newLogFonts and replaces it with a newly allocated copy of logFonts. | or | | newLogFonts[] = logFonts[]; This would work only if newLogFonts had the same length as logFonts. For the same semantics as the Java statement you want newLogFonts[0..nFonts] = logFonts[0..nFonts]; This will not allocate any memory. If the arrays don't have enough space the array-bounds checker will error. | | | TIA, | BA |
Copyright © 1999-2021 by the D Language Foundation