Thread overview
arraycopy in Java --> this in D?
Feb 16, 2004
Brad Anderson
Feb 16, 2004
Vathix
Feb 16, 2004
John Reimer
Feb 16, 2004
Ben Hinkle
February 16, 2004
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
> 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
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
"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