Consilium Technology will be releasing its first commercially deployed .NET MVC 3 e-commerce site soon. Please stay posted for the lessons learnt and technical trials and tribulations, as well as the business challenges.

Posted By:
calc November 04, 2011

You have your mixed mode assembly with a class that holds a pointer to the unmanaged class.

Option 1, old school:

System::Collections::Generic::List^ ClassManaged::GetValues()
{
     // get unmanaged values
     std::vector values = mpUnmanagedClass->getValues();

     array^ managedValues = gcnew array(values.size());

     // pin address of managed class (not moved by clr,
     // managed objects can have their references moved around on the heap)
     pin_ptr dest = &managedValues[0];

     // copy data to managed array
     std::memcpy(dest, &values[0], values.size()*sizeof(double));

     return gcnew List(managedValues);
}

Option 2, take advantage of interopservices.

System::Collections::Generic::List^ DoubleIndexM::GetIndexValues()
{
     // get unmanaged values
     std::vector values = mpUnmanagedClass->getValues();

     array^ managedValues = gcnew array(values.size());

     // cast to managed object type IntPtr representing an object pointer.
     System::IntPtr ptr = (System::IntPtr)&values[0];

     // copy data to managed array using System::Runtime::Interopservices namespace
     Marshal::Copy(ptr, managedValues, 0, values.size());

     return gcnew List(managedValues);
}

Posted By:
calc August 17, 2011

It is simple to wrap unmanaged C++ with C++/CLI by holding a native pointer in the ref class and using it as a proxy. See http://www.codeproject.com/KB/mcpp/quickcppcli.aspx#A8. But what happens when a function in your native class returns an object encapsulated with a std::shared_ptr? (Developers should be using shared_ptr’s in most cases now)

Let’s consider a trivial example. We have a native C++ library that defines what a book is. 1 Book can contain at least one page. And for the sake of simplicity, you can retrieve the number of words for a particular page.

In UML:

In code:


#pragma once

class Page {

public:

     Page(int words);
     ~Page(void);

     int getNumberOfWords() { return m_numberOfWords; }

private:
     int m_numberOfWords;
};

and the book defined as:


#pragma once
#include <vector>

class Page;

class Book {

public:

     Book(void);
     ~Book(void);

     std::shared_ptr<Page> getPage(int pageNumber);

private:

     std::vector<std::shared_ptr<Page> > m_pages;
};

Notice the getPage function returns a std::shared_ptr<Page>. Following the normal pattern of wrapping unmanaged C++ objects, if you wanted to create a wrapper for Page, you would hold a member variable that holds a pointer to the page object. Eg.


public ref class PageRef {

public:

     PageRef(Page* page) : { m_page(page); }
     ~PageRef(void){}

     System::Int32 getNumberOfWords() { return m_page->getNumberOfWords(); }

private:
     Page* m_page;
};

In the above UML diagram, a Book object contains at least 1 page and the pages are managed by a private member variable std::vector<std::shared_ptr<Page>> and you can access a page through getPage which also returns a Page object whose lifetime is managed by a shared_ptr. So how do you return a shared_ptr<Page> object? You can’t make PageRef hold a std::shared_ptr<Page> member variable as the /clr will not allow that. It will only allow holding a pointer to a native object.

We could hold a pointer to a shared_ptr or we could wrap the the shared_ptr with a C++/CLI smart pointer (http://codereview.stackexchange.com/questions/1695/scoped-ptr-for-c-cli-ensure-managed-object-properly-frees-owned-native-object). The link provides an implementation of one such C++/CLI scoped pointer. The CLR scoped pointer ensures the shared_ptr is appropriately released by allocating a new shared_ptr on the heap. The scoped pointer does not allow for transfer of ownership. It holds a pointer to a shared_ptr as a member variable and deletes the resource when it is no longer needed.

Using the clr_scoped_ptr we can now modify the PageRef class:


#pragma once
#include "clr_scoped_ptr.h"

#include <memory>

class Page;

public ref class PageRef {

public:

     PageRef(std::shared_ptr<Page>& page) : m_page(new std::shared_ptr<Page>(page)){}
     ~PageRef(void){}

     System::Int32 getNumberOfWords();

private:
     clr_scoped_ptr< std::shared_ptr<Page> > m_page;
};

The * and -> operators are overloaded in the clr_scoped_ptr so then you can do the following in the PageRef implementation, as per the normal C++/CLI wrapping of unmanaged code pattern:


#include "PageRef.h"
#include "Page.h"

System::Int32 PageRef::getNumberOfWords()
{
     return (*m_page)->getNumberOfWords();
}

Note that I have committed a sin by passing a shared_ptr by reference. However, the purpose of a shared_ptr is to guarantee that  as long as this shared_ptr is in scope, the object it points to will still exist, because its reference count will be at least 1. In this case, we actually maintain that guarantee as we recreate the shared_ptr and allocate it to the heap.

We can then use our native C++ class in C# like so:


static void Main(string[] args)
{
     Library lib = new Library();

     BookRef book = lib.GetBook(0);

     PageRef page = book.getPage(0);

     System.Console.WriteLine(page.getNumberOfWords());
     System.Console.ReadLine(); // wait for user input before exiting console
}

Posted By:
calc June 24, 2011

I have always thought that subversion is most awesome. However, for the past couple of months I have been using Mercurial for some projects and its benefits are beginning to glow ever so brightly. Even more than subversion. Subversion (SVN) is great for linear configuration management and centralised version control whereas Mercurial takes it a step further and allows for distributed version control. I’m not going to take you through a tutorial on the awesomeness of Mercurial. If you want to learn more about Mercurial, Joel Spolsky provides a great explanation/tutorial here. Instead, I would like to show you how you can still claim the benefits of Mercurial even if your existing codebase exists on SVN.

Recently, I came across the problem where I had an existing project with a huge amount of history stored on an SVN repository and I needed to do development work on that project on a computer disconnected from the central SVN repository. So how do you get Mercurial working with SVN?

SVN With Mercurial

You will obviously need to have Mercurial installed. I generally use Mercurial with Tortoise Hg. But I’m sure you’re wondering by now how we will be achieving version control with the existing SVN repository. Luckily there is SVN-Mercurial interoperability.

Use Case

  • Allow for active development of codebase on computer connected to projects SVN repository.
  • Allow for parallel development of the codebase on a computer that is disconnected from the central SVN repository.
  • Maintain version control on disconnected development environment.
  • Merge changes made on remote computer to changes made on connected computer.

Workflow

  1. $hg clone svn+http://my-svn-repository/projectX # this will clone projectX from the SVN repository into a Mercurial (Hg) repository.
  2. Move the cloned repository onto the remote system.
  3. Do some changes, commit those changes, do some more changes and commit them… meanwhile another developer is happily working and committing to the main SVN repository… but all is fine and dandy.
  4. After changes have been made on remote computer. Copy Hg repository back to connected computer, OR get current computer an established connection to the SVN repository.
  5. $hg pull #pull changes from SVN repository into current hg repository.
  6. $hg merge #merge changes made by parallel developer. Resolve any conflicts.
  7. $hg commit #commit merged changes to local hg repository.
  8. $hg push #push changes from local hg repository back to subversion**

**NOTE: In lieu of “hg push” you could also create an SVN patch, $hg di -b -r svnrev([head rev#]):tip > mybugfix.patch.

Posted By:
calc March 19, 2011

A clear case of where you may create an incentive with the intent to improve performance. Be careful what you measure.

I wonder what the outcome might be if you were to provide a $10 bonus for every test case that was created in time x. Sometimes monetary incentives just don’t work.

Posted By:
calc September 20, 2010

If you have installed Windows 7 on your MacBook bootcamp partition and you also run the partition on Mac OSX with VMWare fusion then you will have windows activation problems.

Windows 7 will see your partition install and VM as two separate machines. So if you activated Windows 7 on your VM this will be your genuine copy and when you run Windows 7 from your partition you will get the message, “This copy of Windows is not genuine.”

When a copy of Windows is not recognised as genuine it prevents you from getting online updates. It also prevents any other Microsoft programs like MS Office from performing updates.

The simple solution is, as it is essentially the same install, you run all your updates from the activated machine. In the example above, you can run Windows update and office update from the VM and that will be replicated across both machines.

UPDATE: You can also call Microsoft and advise them of your configuration. They will happily provide you with a separate activation code for the install that is not activated. A much cleaner solution. :)

Posted By:
calc August 18, 2010

Modelling

Modelling is a very unique ability of humans. The concept of abstracting something, reusing it, and reapplying it to another instance. The ability to close our eyes and imagine watching ourselves from a different corner of the room. The ability to empathise with another human being. It has allowed us to develop language, advance technology and mature civilisation. So how can we continue to use modelling today, in technology, socialising and day to day business?

The Modelling Hierarchy

There are four layers in the modelling hieararchy formerly designated as M0, M1, M2 and M3. If we start from the M0 layer, this is what is real, the keyboard you are touching, the screen you are looking at and the chair you are sitting in.

The M1 layer is the first layer of abstraction. For example, the chair that you are sitting in probably has a design drawing created by the manufacturer and this drawing can be reused to mass produce that same chair, likewise with the keyboard and the computer screen.

The M2 layer is yet another abstraction of the M1 layer. In this case, the drawing may have been constructed with a software CAD tool, or hand drawn by a designer. In both instances, the software CAD tool would have been designed and developed for the use of creating designs for real life objects. For the hand drawn design, pencils, paper, rulers and other drawing tools would have needed to be developed to create the drawing. The tools used to create the design could also be used to create designs of other things like a rubbish bin or a car tyre.

The next layer, M3, is where things get a bit tricky, it is an abstraction of the M2 layer. The best way I can explain this, for the current example, is that it represents the concept of creating real-world objects with raw materials. Alternatively, the M0 layer could also be described as a model of a model of a model, or meta-meta-model.

To make things clearer, let’s apply the modelling hieararchy to another concept, language. Starting at the concept of language and communication, the M3 layer. We can instantiate this by creating rules for language. i.e. there should be nouns, verbs, pronouns etc. Essentially, we create a model for creating any language, the M2 layer.

We can then instantiate the M2 layer creating the M1 layer, we could instantiate both French and English as an example. A statement in french might be structured:

[subject pronoun] [conjugated verb] [preposition][definite article][noun][adjective]

However, a statement in English might be structured:

[subject pronoun] [conjugated verb][adjective][definite article][noun]

Finally, we can instantiate the M0 layer by constructing the sentences in both languages. “He ran to the green shop” or “il courut à la boutique verte”.

We can see from the example above that, even at the M2 layer, we could have defined a musical layer of communication, and then gone to define notes and chord structures and instantiated that by creating a song.

In the case of computing, the Meta Object Facility (MOF) is the M3 layer which describes the structure of the Unified Modelling Language (UML), M2. A class diagram, behavioural diagram and use case diagram would be examples of instances of the UML. The models can then be used to create the software code, M1. Note that UML is a modelling language, it is a syntax for modelling. While some people complain about its many shortfalls, its one advantage is that it is a well known standard and meta-model. A non-english speaking russian could essentially communicate an entire software design to a non-russian speaking Australian.

Posted By:
calc July 27, 2010

I would like to share with you some of my favourite resources for knowledge growth, career development and personal development.

Personal Development and Knowledge Growth

http://sethgodin.typepad.com/ – he has fantastic ideas in regards to marketing.

http://www.danpink.com/ – he has a great talk on intrinsic motivation.

http://ted.com – awesome keynote speakers donate cutting edge information for free. All speeches can be downloaded as free mpeg files or simply streamed online. I highly recommend Hans Rosling. Other keynotes include Bill Clinton, Bill Gates, Jamie Oliver and Steve Jobs.

Software Development and Engineering

http://joelonsoftware.com – a great blog for software engineers.

http://codinghorror.com – another great blog for software engineers.

http://stackoverflow.com – a revolutionary forum or question/answer based site for software engineers. It is currently in the process of being applied to all domains.

http://area51.com – a launch platform for the stackoverflow concept into new domains other than software. If you have a great idea then propose it. This could have the potential to be the next layer between the web of data and google. You still have a chance to say “I knew about it before everyone else did!”.

Posted By:
calc July 03, 2010

Since having a child last year, I have already begun to research the different options for education. So I began to write python code in order to scrape the myschool.edu.au website. For the non-developers reading this, scraping is the process of extracting information from published websites using software that mimics the behaviour of a web-browser. I have posted some preliminary results below. The results tabulate the top 5 schools in year 9, SA, for each category, reading, writing, spelling, grammar and numeracy. It is no surprise that all high scoring schools are private schools with a higher percentage of students in the top quarter of the Index of Community Socio-Educational Advantage (ICSEA). There is one exception here, the East Murray Area School scored remarkably in reading and made it in to the top 5 of SA schools and their grammar score was also well above average.

Other results I would like to publish are:

  • the best performing school with a majority of their students being in the lowest quartile of the ICSEA;
  • time series data to show the improvements of schools over time using the gapminder tool. This will be more informative after three or more years of data;
  • heat spot charts using the google maps api showing the normalised performance of schools according to their area. Although, this has already been done for some data;
  • heat spot charts using the google maps api showing the ICSEA value; and
  • heat spot charts showing the median house price value relative to the ICSEA for schools in that area.

If you would like to create your own queries and manipulate the data into views of your own choosing. I have published the code and database which can be downloaded from google code. Alternatively, you can request a particular query in the comments section below and I will endeavour to address it.

Results for South Australia Only:

Top 5 schools for writing:

Schools Score
Wilderness School, Medindie, SA 675
St Dominic s Priory College, North Adelaide, SA 659
Walford Anglican School for Girls, Hyde Park, SA 649
King s Baptist Grammar School, Wynn Vale, SA 644
Seymour College, Glen Osmond, SA 643

Top 5 schools for numeracy:

Schools Score
St Peter s College, St Peters, SA 688
Pembroke School, Kensington Park, SA 665
Wilderness School, Medindie, SA 653
St Peter s Collegiate Girls  School, Stonyfell, SA 651
Pulteney Grammar School, Adelaide, SA 651

Top 5 schools for spelling:

Schools Score
Wilderness School, Medindie, SA 646
Pembroke School, Kensington Park, SA 639
St Ignatius College, Athelstone, SA 635
St Peter s Collegiate Girls  School, Stonyfell, SA 634
Walford Anglican School for Girls, Hyde Park, SA 627

Top 5 schools for grammar:

Schools Score
Wilderness School, Medindie, SA 670
Pembroke School, Kensington Park, SA 651
St Ignatius College, Athelstone, SA 642
Walford Anglican School for Girls, Hyde Park, SA 639
Pulteney Grammar School, Adelaide, SA 636

Top 5 schools for reading:

Schools Score
Wilderness School, Medindie, SA 650
Walford Anglican School for Girls, Hyde Park, SA 645
Pulteney Grammar School, Adelaide, SA 638
Pembroke School, Kensington Park, SA 637
East Murray Area School, Mindarie, SA 636
Posted By:
calc June 24, 2010

Consilium Technology Pty Ltd is a professional services company specialising in software development and technical business analysis.

Software Development Services

Consilium Technology Pty Ltd follows a principle based approach to software development leveraging proven requirements, design, and implementation techniques. Some techniques include but are not limited to:

  • maintaining regular and open communications with the customer;
  • Agile SDLC incorporating a flexible v-model for each iteration;
  • practical use of design patterns;
  • Model Driven Architecture (MDA) with the Unified Modelling Language (UML); and
  • modelling complex legacy systems for improved maintainability;

Technical Business Analysis

Consilium Technology primarily focuses in business analysis at the system layer. That is, taking pre-determined business needs and fulfilling those requirements through the development of system requirements for technical business systems. Clients also have the option of having their technical solution implemented through our software development services.

Posted By:
calc May 09, 2010