Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

VC 10: Stephan T. Lavavej and Damien Watkins - Inside STL

Download

Right click “Save as…”

Visual Studio 2010 Beta 1 introduces a number of exciting new features for the C++ developer as we include a selection of goodies from the upcoming C++0x Standard. We have already heard about many of the language improvements (auto, decltype, lambdas, rvalue references, …) all of which can be put to good use when using the Standard Template Library (STL). Here,  Visual C++ team members who work on the STL – Stephan (Dev), Damien (PM) and a cameo appearance by Usman (QA) – Usman works in our Canadian Development Center and unfortunately could not be onsite for the video - tell us all about the latest version of STL. We talk about how the language features are enabling many improvements to the STL, with performance being a big  beneficiary. To realize these benefits we needed to update our STL implementation to leverage these new techniques, for example adding “move” semantics to STL containers. Additionally  when users of our STL implementation add “move” semantics to their types that they store in our STL containers then we hook into these as well.

Learn more:

http://blogs.msdn.com/vcblog/archive/2009/04/22/decltype-c-0x-features-in-vc10-part-3.aspx

http://blogs.msdn.com/vcblog/archive/2009/02/03/rvalue-references-c-0x-features-in-vc10-part-2.aspx

http://blogs.msdn.com/vcblog/archive/2008/10/28/lambdas-auto-and-static-assert-c-0x-features-in-vc10-part-1.aspx

We did also mention lambdas, decltype, auto (and C++0x, generally) in a C9 PCP video from a while back:

http://channel9.msdn.com/shows/Going+Deep/Parallel-Computing-in-Native-Code-New-Trends-and-Old-Friends/

Tags:

Follow the Discussion

  • CKurtCKurt while( ( !​succeed=try​() ) ) { }

    Hi,

    I might be wrong but when you are talking about Standard C++ you are talking about the C++ not running on the CLR right? I always used "Thinking in C++" from bruce eckel te learn C++.

    Great video !

  • CharlesCharles Welcome Change

    This interview has nothing to do with C++ CLI. It's about C++ and STL (which is a C++ library). The C++ team spends most of their time these days evolving the C++ language, compiler and vast libraries that ship as part of VC++. No longer do they spend inordinate amounts of time figuring out how to shoehorn native into managed. Of course, this doesn't mean they aren't helping the CLR folks with interop issues (not to mention building the compliler that compiles the CLR, Office, Windows, Exchange, etc, etc... Smiley)

    Glad you liked the interview. STL (aka Stephan T. Lavavej) and Damien are great folks.

    C

  • CKurtCKurt while( ( !​succeed=try​() ) ) { }

    So C++ CLI is less recomended? I mean if you want to make it easy you should use C# or VB and if you disside you really want performance and don't mind the extra knowledge you need to make a decent C++ program you should use native C++ and not C++ CLI, right?

  • CharlesCharles Welcome Change

    I'm not saying that C++ CLI is bad.... If you have to interoperate with a bunch of managed code then it makes very good sense, if you're a C++ developer maintaining a big C++ app, for example, to use C++ CLI (it will be more natural to you, anyway).

    As always, use the right tool for the job at hand. There are many C++ (native) developers out there. This interview is targeted at them (especially if they use STL)

    C

  • CKurtCKurt while( ( !​succeed=try​() ) ) { }

    Thanks for the claryfication ! Thanks Charles !

  • after a long pause.. there is a C++ video ... 

    It is sad to hear that the C++ team hasn't got much resources in Microsoft to do the stuff... since C++ is the core behind all of their products... I know the business and market oppertunities are on .Net than C++ now.  I even heard from Damien on last PDC that there were some 40+ people working on the Visual C++ team... for me that was sort of surprising....

    Any how.... Charles.. thanks for the video... you interview people lot better than others on channel 9 Cool

     

  • Stephan is great. He has this uncanny ability to make perfect sense. Brilliant.

  • CharlesCharles Welcome Change

    Indeed. I think it's universally true to all those who know Stephan.

    C

  • CharlesCharles Welcome Change

    You will see more C++ videos in the near future, thanks to Damien, who leads the charge of C++ on C9. Thank you, Damien!

    C

  • Hello

    > “As always, use the right tool for the job at hand.”

    Or as my mother would tell me: “to a man with a hammer everything looks like a nail”.

    I just want to reinforce the comment Charles made above – knowing all the tools of your trade is vital if you want to do any engineering discipline. If you want to build a managed-only application  today, the right tools for that job would be C#/VB/F# (my personal favorite of those would actually be F#– but that is purely my personal preferences coming through Smiley ) If you want to write a high performance native application, then you are probably going to use C/C++. If you want to mix native/managed then write the native parts in C/C++, the managed parts in C#/VB/F# and do the interop shim in C++/CLI (and keep it is small as possible, keep it self contained,  avoid chatting interfaces, … – alternatively you can use PInvoke or COM Interop but I am sure you understand the idea.)

    BTW: Stephan really is as enthusiastic, passionate and knowledgeable as he appears in the video – this is what makers coming to work here every day so enjoyable.

    And as Charles said, we have a few more Channel 9 on the way (the pause was caused by waiting until VS2010 Beta 1 came out – it is so much more fun to describe these features when you can actually play with them too.)

    Thanks

    Damien

  • Or as my mother used to say "When your hammer is C++, everything starts looking like a thumb" Smiley

  • CharlesCharles Welcome Change

    Smiley

  • Hello

    > Or as my mother used to say "When your hammer is C++, everything starts looking like a thumb"

    That is why man evolved to have two thumbs (even way back then someone knew C++ was on the way.) Smiley

    Thanks

    Damien

  • Thanks  Charles... I hope you will get some update from the Managed C++ guys... what are they upto. Hopefully they haven't abandoned the ship yet...

  • Hello

    So on one level we do not actually have “managed C++” guys, when I say I am the PM for the compiler FE and libraries on the Visual C++ team that means both native and managed. To be direct, in VS2010 our focus was on the native developer. With VS2008 and immediately prior releases (in both compiler work - such as “C++/CLI” - and libraries work - such as “STL/CLR” and the “Marshalling Library”) we felt we had devoted sufficient time recently to “managed C++” developers, potentially at the expanse of the native code developer in some ways. So, as you can see in the current beta, there is not that much new for “managed C++” code developers in VS2010. However some of the new features work both ways, try using auto in managed code for example. But I also want to be very clear and respond to your “abandoned” comment, this emphasis on native code development in VS2010 is really a re-balancing of efforts (native had been underdone for a while) and is in no way any indication of relinquishing anything.

    Thanks

    Damien

  • Hi Damien,

         I didn't mean that in a -ve sense. If you felt that way, I am sorry about that. It is just that when the managed C++ got started I thought we could do everything what other managed counter part languages do... but recently I got a feeling that it got down to a language meant for Interop. I actually learned Managed C++ just thinking of the former scenario.  For someone like me who is working for a consultancy or ISV need to be multi skilled, and need to switch to different kind of projects as they come. The problem is I never get to settled down with a technology area ( probably I should quit my job and find another one  Smiley ) The learning time spent on one technology and the knowledge accured is somewhat lost when I switch to another and come back... I guess I have live with that...but I never let I never let go my C++ love, nothing none other gives me the flexibility it provides. It is just that I feel like C++ is not getting there were I wanted it to be.. hopefully the guys in the C++ standard body should speed things up...  I know their problems as well.. so I dont blame them. I have a great respect for you and your team, I hope you don't get me wrong...

    regards

  • Hello

    I took no offence from your statements and did not think you said anything negative. It is just that other readers can accidently read unintended intentions into my posts/replies, so sometimes I find it is just best for me to be super explicit Smiley

    I would agree that recently C++/CLI has found a place as the interop language - while C#/VB/F# add new functionality at a pace that we cannot keep up with if we are also to innovate in the native space as well. And since we are the only native game in the VS box I personally feel we need to devote more time to the native arena then we have in recent releases,

    Personally I am very happy about the new features in C++0x – I agree they took a long time to get here and unfortunately we could not do more of them for VS2010. As we said in the interview, not having variadic templates in VS2010 is Stephan’s and my biggest regret (although we also would also have wanted nullptr too.)

     Thanks

    Damien

  • Hi Damien,

         I really appreciate your reply and the time you took... I know you guys will pull it off in the later VS releases...after all,  something is better than nothing !!!

    Keep up the good work.

    regards

    Saju

  • Deactivated UserDeactivated User

    Comment removed at user's request.

  • Hi,

    I am not sure I am hearing right - the team that wanted you to implement lambdas (approx. 08:00 in video) - is it "PCP"? What does that stand for? (I guess not Power Conservation Program -Smiley

    Thanks, Boris

    Update: oops, should have waited 6 minutes - it's Parallel Computing

  • Hello

    Have a look at this video for more details on the PCP/lambdas work for VS2010: http://channel9.msdn.com/shows/Going+Deep/Parallel-Computing-in-Native-Code-New-Trends-and-Old-Friends/

     Thanks

    Damien

  • Hello

    We do mention somewhere in the video that now we have the re-implementation work completed we will look at performance/cost for the iterator switches and may change the default for VS2010  - no concrete decision yet but stay tuned (as always you will be able to simply switch between the default and whatever you want by defining a macro too.) But we do hear you on the default issue.

    Thanks

    Damien

  • Looking forward to the upcoming series of VC10 videos!  Keep up the great work!

  • Hello

    BTW: both Ale (Contenti) and Louis (Lafreniere) have Channel 9 videos in the pipeline - and we also have a new face on the way too.

    Thanks

    Damien

  • Hello Stephan,

    you briefly mentioned the issue of mixing the 2 layouts of shared_ptr and that they have to match to avoid crashes and worse things. But I am not getting how the library can "know" what layout is used. Consider this:

    auto sp = make_shared<string>("meow");

    shared_ptr<string> sp2 = sp;

    sp expects the string object and refcounts and the deleter object to be in one allocated memory block, sp2 has to expect the string object is in one allocated memory block and refcounts with the deleter object in second allocated memory block.

    Now if in the end, sp is the last one destructed of any shared_ptr sharing content of sp, everything is fine, since sp expects the same layout as the actual one and will do one free.

    But if in the end, sp2 is the last deleted, then it must do 2 frees, when only 1 block has been allocated, which makes the incorrect behavior.

    Only 2 solutions I imagined are:

    1. that shared_ptr constructor from pointer  - shared_ptr<T>(p) - would allocate the one block like make_shared does, initialize refcounts and custom deleter and use new(block)(*p) to copy the object into the block, and then call delete p; since the contents are already copied. But this involves 2 allocations, 1 copy, 1 free, instead of original 2 allocations you demoed on the whiteboard.

    2. Or shared_ptr destruction logic could look if the 2 pointers it contains (to the real object and to the refcounts) differ only by sizeof(T) and dynamically decide which version of destruction to use.

    So could you please explain how do these 2 forms of creating shared_ptr objects coexist together?

    Thanks, Boris

    BTW. thanks for both your videos and all your C++0x blog posts, I am learning a great deal about C++0x from them, just like "release does not exist until you blog about it", I feel like C++0x does not really have a feature until you blog about it Smiley

  • STLSTL

    > you briefly mentioned the issue of mixing the 2 layouts of shared_ptr and that they have to match to avoid crashes and worse things.

    I was referring to the layout of shared_ptr itself. shared_ptr always stores two raw pointers: a pointer to its object and a pointer to its reference count control block. This is true regardless of how the shared_ptr is constructed, whether through the ordinary way or through make_shared().

    What I was talking about in the video was that when you use make_shared(), the pointer to the reference count control block is technically redundant, since the object and the reference count control block live at the same location. However, this redundancy is unavoidable, since make_shared() has to return a shared_ptr, which always stores two raw pointers.

    make_shared() does squeeze out redundancy in what those raw pointers point to - by allocating the object and its reference count control block in a single chunk of memory, it saves one memory allocation's worth of overhead. Also, ordinary construction makes the reference count control block store a raw pointer to the object (this is in addition to the raw pointer to the object stored by the shared_ptr itself), but make_shared() doesn't need to store this; the reference count control block already knows where the object lives.

    > But I am not getting how the library can "know" what layout is used.

    Virtual functions power this particular magic trick.

    Your scenario assumes that shared_ptr's destructor (and reset(), etc.) knows how to delete its owned object, and you're rightly wondering how it can tell the difference between ordinary construction (two dynamic memory allocations) and make_shared() construction (one dynamic memory allocation). But before we get to that, consider shared_ptr's support for custom deleters.

    You can construct a shared_ptr by giving it a raw pointer (obtained from "somewhere") and a custom deleter, which is a functor of arbitrary type. When the last shared_ptr dies, the custom deleter is called with the raw pointer, returning it "somewhere". This is useful, because otherwise shared_ptr expects new/delete. Note the following important fact:

    The custom deleter's type doesn't affect the shared_ptr's type.

    shared_ptr<T> is templated on the object type T, but not on the custom deleter type D. You can, in fact, construct one shared_ptr<T> owning a new T, and another shared_ptr<T> owning a custom-allocated T with a custom deleter D, and each shared_ptr destructor will call the right deleter (plain old delete in the first case, D in the second case). But how is this possible, given that D has arbitrary type? (If it were an arbitrary function pointer of fixed type, void (*)(T *), say, then no magic would be involved.)

    The answer is that when shared_ptr's constructor (or reset(), etc.) constructs a reference count control block, it knows whether it's using a custom deleter or not. (shared_ptr's one-arg ctor takes T *, while its two-arg ctor is templated on D and takes T * and D). shared_ptr stores T * and RefCountBase<T> * (not its real name, of course). RefCountBase<T> has a virtual void DeleteObject() member function. shared_ptr's one-arg ctor constructs a RefCount<T>, derived from RefCountBase<T>, that overrides DeleteObject() and simply calls delete p;. shared_ptr's two-arg ctor constructs a RefCountCustomDeleter<T, D> (this is templated on the deleter's type, since the two-arg ctor is templated on the deleter's type), derived from RefCountBase<T>, that overrides DeleteObject and calls d(p);. The deleter is stored in RefCountCustomDeleter<T, D>. Then, when shared_ptr's destructor (or reset(), etc.) runs, it calls m_refcount->DeleteObject(), where m_refcount is RefCountBase<T> *. This selects the right virtual function.

    This trick is known as "type erasure" (I usually call it "type forgetting"). shared_ptr "forgets" whether it has a custom deleter at all, including what type the custom deleter is, so that the shared_ptr's type isn't affected. But this knowledge is recovered when the object is destroyed, through that virtual function call, so that the custom deleter is properly called if present.

    The same trick is used for make_shared(). When you call make_shared(), it constructs a RefCountUnified<T> object, which stores the T. Its DeleteObject() implementation simply destroys the T in-place. shared_ptr itself doesn't know anything about this, and it doesn't have to. (However, make_shared() must be implemented by the Standard Library, since users can't provide their own reference count control blocks. It's possible to "fake" the single dynamic memory allocation with custom deleter and custom allocator support, but this doesn't result in the same space efficiency.)

    Type erasure is important because it significantly increases shared_ptr's usability. You can pass shared_ptr<T> around without caring where it came from, whether from something with a custom deleter, a custom deleter and a custom allocator, make_shared(), or allocate_shared() (which is make_shared() plus a custom allocator, naturally).

  • Thank you very much for the thorough explanation, now I completely get it! I was familiar type erasure already (e.g. any_iterator, adobe::poly), so it's interesting to see it in action again.

    Thanks again, Boris

  • seems the video is not available anymore.... could you guys check what's going on? thanks

  • CharlesCharles Welcome Change

    There are no problems with the videos. Can you elaborate on the problem you're experiencing? They play fine for me, both inline streaming and download formats. 

  • Hello

    FYI: we just posted on our VC Blog about some STL performance results we have been seeing recently using the new C++0x functionality: http://blogs.msdn.com/vcblog/archive/2009/06/23/stl-performance.aspx

    Thanks

    Damien

  • When I tried to play inline stream, it reported "Media failure." and I got "cannot find server" when I tried to download the mp4 format of the video. I don't know why, maybe it's the network issue?

  • wow, it took C++ only 20 years to correct its most glaring deficiency, the excessive copying on assignment.

Remove this comment

Remove this thread

close

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.