On Mon, 12 Jan 2015 16:32:30 +0000 Oleg via Digitalmars-d-learn <[email protected]> wrote:
> On Monday, 12 January 2015 at 15:59:43 UTC, Adam D. Ruppe wrote: > > Why are you using ref? Take that off and you can pass any > > array, including null, with ease. > > Because dynamic arrays are passed by value to functions. Will it > make another copy of array, if I'll pass array by value? > > Looks like it won't (I've checked pointers), but I read in wiki > (http://en.wikibooks.org/wiki/D_%28The_Programming_Language%29/d2/Strings_and_Dynamic_Arrays#Passing_Dynamic_Arrays_to_Functions) > > that it will copy "structure that contains the -pointer to the > first element- and the length is copied and passed". Does it mean > something else? maybe i don't understand it correctly. nope, it means exactly what is written there. except that dynamic array is represented by struct like this: struct { void *dataptr; size_t itemCount; } this is what D calls "dynamic array", and this is what passed by value: struct with two members. dynamic array contents are *not* a part of "dynamic array type". yes, this is confusing.
signature.asc
Description: PGP signature
