Stefano Tommesani

  • Increase font size
  • Default font size
  • Decrease font size

Parallel loops in the AltaLux kernel

E-mail Print PDF

coloredthreads

The AltaLux plugin for IrfanView is now open-source (here is the GitHub link) and it is worth analyzing the different methods used for parallelizing the computational kernel. The filter factory, contained in the CAltaLuxFilterFactory files, can create one of four possible instance types (actually there's a fifth one that you will never want to use, as we will see later). Most of the plumbing code is hosted in a base abstract class, named CBaseAltaLuxFilter, and there are four specific classes that implement the virtual Run method in different ways:

  1. CSerialAltaLuxFilter
  2. CParallelSplitLoopAltaLuxFilter
  3. CParallelEventAltaLuxFilter
  4. CParallelActiveWaitAltaLuxFilter

Let's start with the first one, the serial implementation, to have an idea of how the code works. Here is the whole Run method:

Last Updated on Monday, 01 February 2016 21:12
 

Transient objects with IoC containers like Castle Windsor

E-mail Print PDF

butlerDependency Injection (DI) and Inversion of Control (IoC) are popular patterns in modern software development that reduce coupling among modules and so improve the testability of the sames. As this article is not meant to be an introduction to DI / IoC, please refer to numerous introductory articles on the net before tackling this topic, as we will delve straight into the implementation's details. For these samples, we will use Castle Windsor as IoC container, and we will build the same sample three times, highlighting the differences in handling permanent and transient class instances with an IoC container. The aim is creating an implementation that has minimal coupling and is highly testable. 

Let's start by drawing the scenario: our simple app uses the IoC container for cross-cutting concerns, in this example only logging but in a real app there could be a lot more functionalities of this kind. e.g. data model access, telemetry and so on. The logging framework is a singleton that spans the whole life of the app, so once we register the interface in the IoC container, and let the container inject the instance into the objects that use it, we are golden. But temporary objects, like a child window, are created and then destroyed when needed, so the same instance cannot span the whole life of the app. At the same time, these temporary objects need to access the functionalities such as logging, so those instances must be injected into the freshly created object.

Let's start with the first implementation to see some real code (before proceeding, download the whole solution from GitHub). The project ManualIoC contains a poor man's implementation of DI, as we have to manually pass the instances to the transient objects. First, let's start with the main program, where we initialize the IoC container:

static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
 
            // create IoC container
            IWindsorContainer container = CastleContainer.Instance;            
            container.Register(Component.For<ILogger>().ImplementedBy<ConsoleLogger>());            
            container.Register(Component.For<MainForm>());            
 
            //Application.Run(new MainForm());
            MainForm mainForm = container.Resolve<MainForm>();
            Application.Run(mainForm);
 
            container.Dispose();            
        }

There are several changes compared to a stock WinForms application: before creating the main form of the app, we create the IoC container, and we register the implementation of the ILogger service, and the MainForm class. Instead of creating directly the MainForm like it happens with the standard WinForms code, we ask the IoC container to resolve, that is returning an instance of the given class, the MainForm and then we run the application. The critical bit is that MainForm requires an ILogger instance in the constructor, and the IoC container knows about it, so it transparently creates a singleton for the ILogger interface using the ConsoleLogger implementation and passes it to the constructor of MainForm, without requiring any intervention from our side. With a simple demo it is hard to understand how an IoC controller can simplify a real project, but assume that there is not just one cross-cutting functionality like logging in the example, but many more and you will understand how the code gets clearer and simpler. Also, rewiring the app to use a different logging framework requires just creating a new implementation of the ILogger interface that uses the new framework, and changing just the registration of the ILogger interface in this bit of code.

Last Updated on Monday, 01 February 2016 20:58
 

AltaLux filter for IrfanView is now open-source!

E-mail Print PDF

I have just released the new version of the AltaLux plug-in for IrfanView on GitHub, clone it now!

There are some good reasons for taking a peek:

  • having a look at how to write a plugin for IrfanView
  • discovering how the AltaLux algorithm works
  • comparing different ways to divide the computation kernel in various threads

And don't forget to download the new version of the plugin, in both 32- and 64-bits versions, from the download section!

StefanoT_AltaLux-IrfanView

 

The best Diff so far

E-mail Print PDF

We recently heard about two really far branches in our codebase. Your mission, should you choose to accept it, is finding the changes and merging them.

So I try a GIT diff within Atlassian SourceTree, my GIT client of choice, and the result is unusable: the developers not only made a lot of changes within the same functions, but they also moved functions across the source file, and diff is trying to reconcile different pieces of code that have some similarity.

Enter WinMerge. More or less, the result is comparable to what I had with GIT, back to square one.

After a search on the net, I have found DiffMerge from SourceGear. Running it on the same code, I got a vastly better result, as it recognizes that is parsing C++ code and seems to use function definitions to resynch changes, this way avoiding reporting similar lines of code from different functions as a match. Of course, it does not track functions moved across the source file, but it is fairly easy to spot them, as they appear as code blocks appearing only on the left or right column in the trackbar on the left.

Mission accomplished!

Diff

 

How you rank for profile views in LinkedIn

E-mail Print PDF

#1 of 100 in Professionals like me

LinkedInRank1

Last Updated on Sunday, 15 February 2015 13:30
 

Opening password-protected PowerPoint presentations

E-mail Print PDF

PowerPoint presentations can arrive in different file formats:

  • PPT is the default file extension for saving presentations in PowerPoint 2003 and earlier versions.
  • PPTX is the default file extension for saving presentations in PowerPoint 2007 and later versions.
  • PPS is the the show mode extension in PowerPoint 2003 and earlier -- these files run in "play-presentation" mode when double-clicked.
  • PPSX does the same thing in PowerPoint 2007 and later -- it runs in "play-presentation" mode when double-clicked.

For editing a PPSX file, instead of double clicking on it, as it would start the "play-presentation" mode, open PowerPoint and then open the file:

PPSXpowerpointopen

Still, if the PPSX file is password-protected, you have to enter the correct password to unlock it and be able to alter the contents and paste them in other presentations:

PPSXopenfile

Or not?

Last Updated on Sunday, 23 November 2014 12:49
 
  • «
  •  Start 
  •  Prev 
  •  1 
  •  2 
  •  3 
  •  4 
  •  5 
  •  6 
  •  7 
  •  8 
  •  Next 
  •  End 
  • »


Page 1 of 8
View Stefano Tommesani's profile on LinkedIn

Latest Articles

Parallel loops in the AltaLux kernel 12 January 2016, 21.03 Multi-thread
Parallel loops in the AltaLux kernel
The AltaLux plugin for IrfanView is now open-source (here is the GitHub link) and it is worth analyzing the different methods used for parallelizing the computational kernel. The filter factory, contained in the
Transient objects with IoC containers like Castle Windsor
Dependency Injection (DI) and Inversion of Control (IoC) are popular patterns in modern software development that reduce coupling among modules and so improve the testability of the sames. As this article is not meant to be an
AltaLux filter for IrfanView is now open-source! 02 November 2015, 19.09 Software
AltaLux filter for IrfanView is now open-source!
I have just released the new version of the AltaLux plug-in for IrfanView on GitHub, clone it now! There are some good reasons for taking a peek: having a look at how to write a plugin for IrfanView discovering how the
The best Diff so far 07 June 2015, 12.20 Software
The best Diff so far
We recently heard about two really far branches in our codebase. Your mission, should you choose to accept it, is finding the changes and merging them. So I try a GIT diff within Atlassian SourceTree, my GIT client of choice,
How you rank for profile views in LinkedIn 15 February 2015, 11.50 Web
How you rank for profile views in LinkedIn
#1 of 100 in Professionals like

Translate

Hanselminutes
Hanselminutes - Fresh Air for Developers is a weekly talk show that brings interesting people together to talk about the web, culture, education, technology and more. Hosted by Scott Hanselman, this show promises fresh ideas and great people.