A Simple Cache for C++/CLI

C/C++ for has always been a side affection of mine, although I’ve never been able to land a job that required it.  As such several years ago when the Managed Extensions for C++ came into being I gave them a whirl.  Oh my god… what an ugly, ugly thing those extensions were.  With disappointment I promptly left them alone and continued my journey into the world of C# and took several willing people with me. 

Then, after some delay VS2K5 came into being and I immediately got myself a copy as part of my MSDN and entered the wonderful world of .NET 2.0.  I saw some articles of C++/CLI, but after the Managed Extensions I must admit I ignored them for a year.  That is until last November when this book was released by APress… ‘Pro Visual C++ 2005 for C# Developers’.  So for old times sake and because the sterling to dollar exchange rate favoured me, I purchased the eBook for a tenner and had another go.

Wow.  What a change.  C++/CLI is sweet.  Okay, it’s got a few low points, but those are more to do with ANSI compliance than anything else.  The inline CIL would have been nice, and the ability to move objects around the CRT/CLR heaps would have been handy – ‘all in good time’ we are promised.  Well, we will see.  But all that aside, I am well impressed.  The deterministic destruction is nice syntactic sugar, but welcome all the same.  The tight CIL the compiler generates is a wonderful surprise, although the native/managed transition is a little slower than I would have liked – much better than the P/Invoke for speed if you don’t mind losing verifiability.

So... As part of my refamiliarisation with C++, I am converting some of my more useful classes as a learning tool.  So, please enjoy the C++/CLI version of SimpleCache (click here for c# version):

SimpleCache.h for C++/CLI