Sunday, December 19, 2010
Many people really don't understand where P/Invoke signatures come from, or what they mean. They head over to pinvoke.net, which - don't get me wrong - is a hugely important resource, and then blindly paste in whatever they find and try compiling and running their code. Or they use the superbly helpful P/Invoke Interop Assistant. Again, paste, build, run, works on my machine. This is a great way to start. The problem is assuming that once one run worked, you're done. You need to read and understand the P/Invoke signature you are using. Especially when you are passing in a pointer, or getting a pointer back, you must know who owns that memory and who will clean it up. Are you handing it over to the native code to manage? Is there a risk your managed code will clean it up before the native code is done with it? Is there a risk the native code will clean it up, and then later the managed code will also try to clean it up? Don't think these things don't happen, they most certainly do. Here's an example: a long running intermittent bug that was caused by a P/Invoke declaration that said the managed side would clean up, but that should have said the native side would (since the native side did.) And here's a nice summary of ways to make sure that native resources (like handles) aren't cleaned up too soon by the managed side. Sorry, but you need to understand this stuff in order to interop successfully. That's where the phrase "head spinning interop" came from, after all. Don't like it? Don't want to learn it? Then use an interop library like the Code Pack that takes care of those sorts of things for you and exposes an entirely managed interface. Have to learn it whether you want to or not? Consider using the Code Pack as a reference for how to do interop properly. The full source code is available, and nicely commented too. Kate
Friday, December 17, 2010
It's over 200 pages long, and over four years old, but I just heard about it recently. A long, dense discussion of whether certain C++ features (templates, namespaces, RTTI, etc) have a performance cost, and how to write code that incurs as little performance cost as possible. Its official name: ISO/IEC TR 18015:2006(E) Technical Report on C++ Performance. In addition to runtime performance, it also touches on compile slowness, the "brittle base class" problem, and the different performance characteristics of various STL collections and algorithms. If you care about the speed of your C++ code, you should read this, even if some of it is already familiar to you. I'd like to give some kind of "Restrained Understatement" award to this sentence: Template meta-programming and expression templates are not techniques for novice programmers, but an advanced practitioner can use them to good effect.
To be clear about where these authors are placing the "advanced" bar, I don't use meta-programming, I consider it too advanced for me. And I have 20+ years of C++! The whole report is platform independent (though embedded systems are discussed separately) and compiler independent, too. I wish it were updated for C++0x, but I guess that will have to wait until C++0x is settled . There's a 14 page bibliography, and you would do well to read many of them, though my source for the link winkily pointed out another possible paper. That one is old enough to get a driver's license, but I think you might enjoy reading it anyway. As the introduction begins: It is important to understand how your programming language is implemented. Such knowledge dispels the fear and wonder of “What on earth is the compiler doing here?”; imparts confidence to use the new features; and provides insight when debugging and learning other language features. It also gives a feel for the relative costs of different coding choices that is necessary to write the most efficient code day to day.
It's only 23 pages long, and concludes: ... we have considered many of the significant C++ run-time implementation issues. We see that some wonderful language features are almost free, and others can incur significant overhead. These implementation mechanisms are applied quietly for you, behind the curtains, so to speak, and it is often hard to tell what a piece of code costs when looking at it in isolation. The frugal coder is well advised to study the generated native code from time to time and question whether use of this or that particularly cool language feature is worth its overhead.
Good advice, in 1994 or 2010. Kate
Wednesday, December 15, 2010
Those hardworking elves at the All in One Code Framework keep releasing more samples. They've added some ASP.NET samples (including a very interesting "get location from IP address" one) and some Windows 7 shell extensions, specifically a preview handler. Ah, the good old .recipe file type - an old friend of mine. But as always the samples are going to save you hours and hours of time. Here's an index to all the samples for you to explore. You might be a little astonished if you haven't checked it out before, they have: Slowly but surely the samples are accumulating to live up to the name. This should be the first place you look when you want to take on a new task. Generally speaking, everything is available in native C++, C#, and VB (the exceptions are things you can't do in native C++, like ASP.NET) with the language included in the sample name (look at CppWin7TriggerStartService, CSWin7TriggerStartService, and VBWin7TriggerStartService for example.) And remember, if you don't see what you want - you can ask for it! Kate
Monday, December 13, 2010
At the moment these are announced in the USA only. A full day of client development training for Windows 7, including IE9 and SL OOB. They say: We will look at application compatibility and transitioning your applications to
Windows 7, integrating with the Windows taskbar, developing for IE9, utilizing
the cool functionality in the Sensors and Location Platform so that your
application better responds to its current environment, leveraging the
multitouch capabilities (especially in kiosk scenarios), and creating
Silverlight 4 out of browser applications. This event is a unique opportunity,
partnering classroom learning with hands-on-labs and leveraging experts to
advise you so we can help you “win” with Windows 7.
You bring your own laptop with VS 2010, the Code Pack, the Windows 7 Training Kit, IE9, and Silverlight 4 installed (there are links on the bootcamp page) and do the labs as you go. The training is all free and you'll get hands on experience right while you're there. (It doesn't say so, but my guess is this is all managed code and that the labs are in both C# and VB.) And if there isn't one near you, you can help arrange one! It's all packaged as an event-in-a-box so all you need is a trainer who'll agree to deliver it and a room to hold it in. But check the dates and locations first -- there are over a dozen sessions scheduled already, so perhaps there's one near you. Kate
Saturday, December 11, 2010
Back on December 7th, Jason Zander announced the beta of Service Pack 1 for Visual Studio 2010. December announcements can often go un-noticed, but you should pay attention to this one. You can get the beta and start using it in production immediately. What's in it, and why does a service pack matter, anyway? Well this one brings Silverlight 4 Tools for Visual Studio "into the box", updates some MFC capabilities, and fixes things people raised on Connect. (Remember, complaining about missing features or bugs to your cubicle mates may make you feel better, but raising them on Connect gets them fixed. I should know, I submit things there and they get fixed.) STL has a comment on the VCBlog post that spells out many of the fixes in detail. Take a few minutes and update your Visual Studio, especially if you're a C++ developer, whether MFC or C++0x (or both, of course.) Kate
Thursday, December 09, 2010
Herb Sutter has blogged a "trip report" (except he didn't travel, but anyway) about the November meeting of the C++ Standards Committee. In it, he tells us: Things are going well and we are on track to complete the Final Draft
International Standard (FDIS) for the C++0x standard after the Madrid meeting in
March. If that happens and that ballot succeeds, the C++0x standard will be
published in 2011. There are still decisions being made, and I have to say I like the way they're going. I think contextual keywords are wicked smart, and that if compilers can understand them, developers sure can. Compare Herb's two examples:
class [[base_check]] Derived : public Base { public: virtual void f [[override]] (); virtual double g [[final]] ( int ); virtual void h [[hiding]] (); }; | class Derived explicit : public Base { public: virtual void f () override; virtual double g( int ) final; virtual void h() new; }; |
Contextual keywords make the second option possible, and I think it's much better. You can also read about noexcept and the whole exception-checking backstory, as well as rules for generating move constructors and move assignment operators. It's all good.
Kate
Tuesday, December 07, 2010
Windows 7 developers have tons of cool stuff at their (our) fingertips. There's taskbar integration, the new sensors and location platform, access to devices, and more. Silverlight developers, on the other hand, have so far not been able to get to all of that. Well, now you can! The Native Extensions for Microsoft Silverlight leverages the ability of Silverlight to do COM integration, and puts COM Automation around a collection of Windows 7 functionality so that Silverlight developers can use it. How cool is that? Because it's on the Code Gallery, you know it's from Microsoft. The first release, Dec 2nd, covers: - Windows Sensor API - Integrate sensors: Accelerometers, Light sensors, compasses, gyroscopes etc.
- Microsoft Speech API - Text to Speech (Speech Synthesis) and Speech to Text (Speech Recognition)
- Windows Portable Devices API - Enumerate and access content from connected portable devices (cameras, phones, music players, scanners etc.)
- Windows 7 Taskbar Integration - Jump lists, overlay icons, overlay progress display, Thumbnail toolbars etc.
- Webcam Local Encoding and Window Capture - Encode webcam capture into mp4 (H.264/AAC-LC) media - Capture user interface interaction as video
- Window Message Interception - Intercept and act on Window messages sent to the Silverlight OOB host window
This certainly gives Silverlight developers some interesting options! There are some samples that come with the library to show you what you can do, too. You might also be interested in Maor David's blog entry about the library.
Sunday, December 05, 2010
I finally caught up some of my PDC-watching and really enjoyed this Herb Sutter talk on C++0x lambdas. I'm well known to be a huge lambda fan. Herb made this talk enjoyable for me by bringing his personality to the table. He showed aspects of C++ that are not exactly elegant, and how using lambdas can make some much neater code possible. Sure, lambdas are "just" syntactic sugar, but they add up to a new way of thinking about writing applications in C++. Well worth watching. One warning though - I generally download videos and watch them at 1.5 or double speed. I highly doubt you want to do that with this talk - it's dense! Kate
© Copyright 2024 Kate Gregory
Theme design by Bryan Bell
newtelligence dasBlog 2.3.9074.18820 | Page rendered at Friday, December 06, 2024 5:39:50 AM (Eastern Standard Time, UTC-05:00)
|
On this page....
Pluralsight Free Trial
Search
Navigation
Categories
Blogroll
Sign In
|