Timon Gehr Wrote: > On 08/30/2011 03:20 AM, bearophile wrote: > > Timon Gehr: > > > >> bar(array(map!((int[] a){return a;})(multi[]))); > > > > Simpler: > > bar( array(map!q{ a[] }(multi[])) ); > > And buggy. It returns slices of a local stack frame, because static > arrays are value types.
q{ a[] } does the same thing as (int[] a){return a;}, both return a slice of memory on the stack. Using a dynamic array (a slice) that uses memory allocated on the stack is correct. You just have to know what you are doing. It's the same as passing a fixed-sized array to a function that expects a dynamic slice. Andrej Mitrovic has said: "I was just trying to temporarily avoid GC allocation so I've used a static array instead of a dynamic ones." If you replace the map function with q{ a.dup } you have heap memory, but Andrej is not happy. Bye, bearophile