STL/CLR is not what I (we?) expected! RRS feed

  • Question

  • Ok, the longly awaited STL.Net was born and its name is STL/CLR!
    Now, I took a look on the demo source code provided with VS2008. Basically it shows that you can pass a vector<> from C# down to C++ native... fine. Except that if you look to the critical part of the sample source code:
    void StlClrLibrary::Tools::BubbleSortNative(System::Collections::Generic::IList<System::String^>^ list)  
        // marshal to a native local vector first  
        std::vector<std::string> native_vec;  
        for each(System::String^ str in list)  
        // calling a native function that will do the sorting  
        // marshal back the list  
        int i = 0;  
        for each(std::string str in native_vec)  

    This really looks like a plain, ugly solution... did I miss something or are they simply duplicating items each by each in order to transfer them from GC memory to native mode? If this is so, it looks to me that STL/CLR is not useful for interop:
      1. You can already copy item per item a List from C# to C++ native vector, no need for STL/CLR for that. 
      2. If speed and memory is important (which is often the case when you use Interop, right?) then you can use can an Array from C# and pass it directly to native C++, without any mashalling or duplication, just using pin pointers.

    I really hope I missed the point and wait for your help to explain me, thanks!

    Wednesday, October 1, 2008 6:16 PM


  • Nishant Sivakumar had some trouble coming up with a good justification to consider STL/CLR.  Gotta be the bubble-sort.  If you're looking for anybody using this, you'll have to post to the C++ General forum.  Haven't seen anybody there yet.

    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Wednesday, October 8, 2008 10:08 AM
    Thursday, October 2, 2008 1:16 AM