D - arraycopy in Java --> this in D?
- Brad Anderson (10/10) Feb 15 2004 Java:
- Vathix (3/12) Feb 15 2004 I don't know Java but I can explain what the difference is. dup creates
- John Reimer (5/17) Feb 15 2004 If these two arrays are dynamic (declared []), I think you need the
-
Ben Hinkle
(23/23)
Feb 15 2004
"Brad Anderson"
wrote in message news:c0p5ee$31g2...
Java: ------------- System.arraycopy (logFonts, 0, newLogFonts, 0, nFonts); D: ------------- newLogFonts = logFonts.dup; // do I need the .dup? or newLogFonts[] = logFonts[]; TIA, BA
Feb 15 2004
newLogFonts = logFonts.dup; // do I need the .dup? or newLogFonts[] = logFonts[]; TIA, BAI 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.
Feb 15 2004
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;)
Feb 15 2004
"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
Feb 15 2004