From: David P. <dpi...@me...> - 2010-12-03 20:01:58
|
> DP> Why would you want List<T> instead of IList<T>? > > As I tried to explain in my original message, solely for convenience. To do the > latter you need the intermediate class (implementing IList<T>) which is > rather alien from C# programmer point of view. The user can declare his variable as IList<T>, which is not alien. Try this typemap instead if you wish to hide the wrapper: %typemap(cstype) std::vector<double> "System.Collections.Generic.IList<double>"; Now there is no need to make a copy of the vector. Admittedly, memory management could be an issue in some cases, which is the only real advantage to duplicating the vector<T> as List<T>. > DP> Returning List<T> is very inefficient, as a copy of the entire list > DP> must be made. > ... > and then write > > List<double> values = vd.GetValuesUpTo(N); > for (int i = 0; i < values.Count; i++) > Console.WriteLine("{0}", values[i]); > > there are no calls to C++ code after the first line. You assume the user will store the result in a local variable. If he's calling a method() then he likely will, but if the vector is returned from a variable or property, he likely won't. |