Leave a comment

C++11 Greatness, WinRT Greatness

I have bought myself a massive book, “Professional C++ – Second Edition”, and I am working through it. I have also downloaded and watched various talks covering C++11 and WinRT, from the Microsft BUILD converence that was held in Anaheim, California. I watched presentations by people like (the legendary) Herb Sutter. I have consequently started to re-write my whole Farve artificial intelligence system in C++.

One word: C++ has always been the best, and with the new language features in C++11 it is not just still the most efficient programming language in the world, but it has native support for all the modern concepts found in ‘higher-level’ languages like C# – properties, delegates, events, lambdas… not to mention the library objects it had for long now in the STL, things like shared_ptr…

OK that was not one word, it was one paragraph though. C++ is back baby. And now also with the MOST powerful support for WinRT programming (the Windows Runtime – it truly is, as Microsoft say – a bold new reimagining of Windows). Oh yes, and C++ AMP – Accelerated Massive Parallelism – writing code that runs tens or hundreds of times faster, on DirectX hardware… it is.. beautiful.

There is little doubt in my mind – my language of choice is C++ again. The ease of C# – any monkey can code in C# – has for a time lured me away from my first love, which is C++. But now I feel guilty for having left.

Don’t get me wrong – .NET is nice. It is very nice!

But nice is just… nice. C++ is more than ‘just nice’. And C++11 is, as of this writing, the best programming language there is, IMHO.

As Herb Sutter kept pointing out in his presentations – C++11 is Clean, Safe, and Fast.

And I am very impressed with the details of Windows 8! It is really impressive. The WinMD (Windows Metadata – which makes the whole Windows Metro API available to ANY language – hence the ability to use JavaScript, for example) is great. The new object-oriented API, with namespaces and interfaces etc, is great. The language projections are great. Oh and the native support in Microsoft C++!! for the WIndows Runtime, and the fact that C++ is IDEAL for it (since it is, at the core, an extension of COM), is great.

So much to learn!!

Leave a comment

DirectX 11 in native C++ 11.

Success :)

Leave a comment

Hello

Hello, readers.

I have not posted here for a very long time, my apologies for that.

So, what is new in my life? Not much, it is still mostly boring. But I can write a few words.

I find that in this time of the Christmas feeling starting to come again, I sometimes think of Lorena. I find that I miss her, then it changes to anger because of her deception, then it turns to worry (since I just never heard of her, some part of me will always wonder if maybe something bad happened to her, instead of she just leaving me). Anyway, she is thoroughly in my past. I hope to soon meet someone special again.

I have started a new technical document for Farve, my artificial intelligence. The document is titled “Principles of Intelligent Systems”. It is where I accurately document my EXCON neural network architecture for now – later I will add details pertaining to other aspects of Farve (non-neural-network aspects). But EXCON is the big one to get right now. I have proven that the concept works – now I am refining it and building something functional.

I am going on leave soon! I am very tired and stressed, this has been a tiring year for me. I look forward to my holiday. I am going to party December away !!!! :)

The end of the world is next year. So I hope y’all enjoy the little time we have left. As a species, we did not get very far hey? We are going to go extinct next year, and we have not even achieved interstellar travel, or colonised another planet. That sucks! :)

http://news.nationalgeographic.com/news/2009/11/091106-2012-end-of-world-myths.html

Cheers!

Leave a comment

What is WinRT – Short and Sweet

By Steve Rowe:

The Windows Runtime is exposed using API metadata (.winmd files). This is the same format used by the .NET framework (Ecma-335). The underlying binary contract makes it easy for you to access the Windows Runtime APIs directly in the development language of your choice. The shape and structure of the Windows Runtime APIs can be understood by both static languages such as C# and dynamic languages such as JavaScript. IntelliSense is available in JavaScript, C#, Visual Basic, and C++.

In short, Windows Runtime is a new set of libraries exposing Windows functionality and available to JavaScript/C#/VB/C++. Each language has been made to understand and be able to call them directly rather than having to go through some thunking layer.

Silverlight and WPF are flavors of XAML that run on the CLR. Among other functionality, Windows Runtime exposes a version of XAML very similar to Silverlight, but does so in a native way, not via the CLR. It can be accessed from the CLR, but also from C++.

Leave a comment

What exactly is ‘WinRT’, the new ‘Windows Runtime’ in Windows 8?

I have been studying this for a couple of days, it can be confusing at times. The reason is because programming languages are often part of the discussion. I found the following explanation of WinRT, by Pavel Minaev – I think it is a very good explanation.

———-
At the lowest level, WinRT is an object model defined on ABI level. It uses COM as a base (so every WinRT object implements IUnknown and does refcounting), and builds from there. It does add quite a lot of new concepts in comparison to COM of old, most of which come directly from .NET – for example, WinRT object model has delegates, and events are done .NET-style (with delegates and add/remove subscriber methods, one per event) rather than the old COM model of event sources and sinks. Of other notable things, WinRT also has parametrized (“generic”) interfaces.

One other big change is that all WinRT components have metadata available for them, just like .NET assemblies. In COM you kinda sorta had that with typelibs, but not every COM component had them. For WinRT, the metadata is contained in .winmd files – look inside “C:\Program Files (x86)\Windows Kits\8.0\Windows Metadata\” in Developer Preview. If you poke around, you’ll see that they are actually CLI assemblies with no code, just metadata tables. You can open them with ILDASM, in fact. Note, this doesn’t mean that WinRT itself is managed – it simply reuses the file format.

Then there are a number of libraries implemented in terms of that object model – defining WinRT interfaces and classes. Again, look at “Windows Metadata” folder mentioned above to see what’s there; or just fire up Object Browser in VS and select “Windows 8.0″ in the framework selector, to see what’s covered. There’s a lot there, and it doesn’t deal with UI alone – you also get namespaces such as Windows.Data.Json, or Windows.Graphics.Printing, or Windows.Networking.Sockets.

Then you get several libraries, which are specifically dealing with UI – mostly these would be various namespaces under Windows.UI or Windows.UI.Xaml. A lot of them are very similar to WPF/Silverlight namespaces – e.g. Windows.UI.Xaml.Controls is closely matching System.Windows.Controls; ditto for Windows.UI.Xaml.Documents etc.

Now, .NET has the ability to directly reference WinRT components as if they were .NET assemblies. This works differently from COM Interop – you don’t need any intermediate artifacts such as interop assemblies, you just /r a .winmd file, and all types and their members in its metadata become visible to you as if they were .NET objects. Note that WinRT libraries themselves are fully native (and so native C++ programs that use WinRT do not require CLR at all) – the magic to expose all that stuff as managed is inside the CLR itself, and is fairly low level. If you ildasm a .NET program that references a .winmd, you’ll see that it actually looks like an extern assembly reference – there’s no sleight of hand trickery such as type embedding there.

It’s not a blunt mapping, either – CLR tries to adapt WinRT types to their equivalents, where possible. So e.g. GUIDs, dates and URIs become System.Guid, System.DateTime and System.Uri, respectively; WinRT collection interfaces such as IIterable and IVector become IEnumerable and IList; and so on. This goes both ways – if you have a .NET object that implements IEnumerable, and pass it back to WinRT, it’ll see it as IIterable.

Ultimately, what this means is that your .NET Metro apps get access to a subset of the existing standard .NET libraries, and also to (native) WinRT libraries, some of which – particularly Windows.UI – look very similar to Silverlight, API-wise. You still have XAML to define your UI, and you still deal with the same basic concepts as in Silverlight – data bindings, resources, styles, templates etc. In many cases, it is possible to port a Silverlight app simply by using the new namespaces, and tweaking a few places in code where the API was adjusted.

WinRT itself doesn’t have anything to do with HTML and CSS, and it bears relation to JavaScript only in a sense that it is also exposed there, similar to how it is done for .NET. You don’t need to deal with HTML/CSS/JS when you use WinRT UI libraries in your .NET Metro app (well, I guess, if you really want to, you can host a WebView control…). All your .NET and Silverlight skills remain very much relevant in this programming model.

———-

Very exciting stuff.

One thing I would like to know is, how does WinRT performance compare to .NET? WinRT is not managed, so I suspect it will be slightly faster than .NET. Is that the case? Will a C# application that targets WinRT run faster than a C# app that targets .NET? Is a C# app that targets WinRT unmanaged now, or is it still managed? That is my question.

Cheers.

Leave a comment

Genetic Mutation

I am thinking about introducing genetics into Farve neural networks, and it occured to me that genetic mutation can be regarded as a form of a randomized brute-force searching algorithm. Think about that and let me know what you think.

Cheers for now.

Oh, hey Gabriella – it was nice to see you at Tings an’ Times last night! I was very surprised to see you – speechless actually. I mean, what are the chances? Based on how seldom I go out, very very slim. Chance – a interesting topic.

Leave a comment

I have reached my target neural network size

I have just successfully allocated 1 Hundred Million Nodes in a neural network. This was just to see if my PC and my program could handle it. I had to compile this for x64 because 32 bit mode cannot handle the memory allocation above about 2GB. But x64 works beautifully.

But size is just promise of additional capability – more important is architecture. SO I am back to much smaller, much more specialized neural circuits.

Leave a comment

15 Million Node Neural Network on old 1GB PC

So, do you want proof that C/C++ is better than managed languages like C#?

I have recently started rewriting my Farve Extensive Connectivity Neural Network system in unmanaged C++. My own PC is broken so I am using my mother’s old PC, with 1GB RAM. On this PC, I just created an Extensive Connectivity neural network consisting of 15 Million nodes, and to allocate all that took just 20 seconds.

15 Million nodes.

Leave a comment

Enter the Functor

The same program as in my previous post, but this time with a functor (overloaded () operator) to make the syntax very easy and C#-like:

#include
#include

using namespace std;

int main();
void myfunc();
void myfunc2();
void myfunc3();

class CDelegator
{
private:
std::vector _functions;

public:
void operator()()
{
Fire();
}

void operator+=(void (fn)())
{
AddFunction(fn);
}

void AddFunctionPtr(void (*fn)())
{
_functions.push_back(fn);
}

void AddFunction(void (fn)())
{
_functions.push_back(*fn);
}

void Fire()
{
vector::iterator iter;
for (iter = _functions.begin();
iter<_functions.end();
iter++)
{
cout << &*iter <>t;
return 0;
}

void myfunc()
{
cout << "MyFunc" << endl;
}

void myfunc2()
{
cout << "MyFunc2" << endl;
}

void myfunc3()
{
cout << "MyFunc3" << endl;
}

Leave a comment

C / C++ wonderfulness

Some of you might know that I am re-learning myself C and C++. Why? Because C and C++ are the most powerful computer languages on the planet.

After chatting to a work colleague, Siegfried, I decided to try to implement delegate-like functionality in C. I am very happy to say that my small test program is a complete success.

Here is the code:


#include
#include

using namespace std;

int main();
void myfunc();
void myfunc2();
void myfunc3();

class CDelegator
{
private:
std::vector _functions;

public:
void AddFunctionPtr(void (*fn)())
{
_functions.push_back(fn);
}

void AddFunction(void (fn)())
{
_functions.push_back(*fn);
}

void Fire()
{
vector::iterator iter;
for (iter = _functions.begin();
iter<_functions.end();
iter++)
{
cout << &*iter << endl;

void(*func)();
func = *iter;
func();
}
}
};

int main()
{
CDelegator delegator;

delegator.AddFunction(myfunc);
delegator.AddFunction(myfunc2);
delegator.AddFunction(myfunc3);

delegator.Fire();

return 0;
}

void myfunc()
{
cout << "MyFunc" << endl;
}

void myfunc2()
{
cout << "MyFunc2" << endl;
}

void myfunc3()
{
cout << "MyFunc3" << endl;
}

Follow

Get every new post delivered to your Inbox.