« Sound and Vision | Source Code Archives | Testing »

Practical Testing: 33 - Intrusive multi-map.

| 0 Comments
Previously on "Practical Testing"... I'm in the process of replacing STL containers with custom intrusive containers in the timer system that I have been developing in this series of articles. The idea is that the intrusive containers do not require memory operations for insertion or deletion as the book-keeping data required to store the data in the container has been added to the data explicitly. This reduces the potential contention between threads in the application and, hopefully, improves overall performance. In the last instalment I showed how my usage of std::set in the timer wheel code could be replaced by…

Practical Testing: 32 - Intrusive containers.

| 0 Comments
Back in 2004, I wrote a series of articles called "Practical Testing" where I took a piece of complicated multi-threaded code and wrote tests for it. I then rebuild the code from scratch in a test driven development style to show how writing your tests before your code changes how you design your code. Since the original articles there have been several bug fixes and redesigns all of which have been supported by the original unit tests and many of which have led to the development of more tests. In 2010 I needed to improve the performance of the code…

Practical Testing: 31 - A bug in DestroyTimer.

| 0 Comments
Back in 2004, I wrote a series of articles called "Practical Testing" where I took a piece of complicated multi-threaded code and wrote tests for it. I then rebuild the code from scratch in a test driven development style to show how writing your tests before your code changes how you design your code. Since the original articles there have been several bug fixes and redesigns all of which have been supported by the original unit tests and many of which have led to the development of more tests. Whilst doing some development on a new server design I managed…

Practical Testing: 30 - Reducing contention

| 2 Comments
Previously on "Practical Testing"... I've been looking at the performance of the timer system that I developed and have built a more specialised and higher performance timer system which is more suitable for some high performance reliable UDP work that I'm doing. Whilst developing the new timer wheel I began to consider the thread contention issues that the timer system faced and came up with a notation for talking about contention (see here). Both the general purpose timer queue and the new timer wheel suffered from more potential thread contention that they needed to because of the way the STL…

Practical Testing: 29 - Fixing the timer wheel

| 0 Comments
Previously on "Practical Testing"... I'm writing a timer wheel which matches the interface used by my timer queue. This new implementation is designed for a particular usage scenario with the intention of trading space for speed and improving performance of some reliable UDP code. The last entry completed the development of the timer wheel. This time we fix a couple of the bugs that I've discovered since I started to integrate the code with the system that it was developed for.…
Previously on "Practical Testing"... I'm writing a timer wheel which matches the interface used by my timer queue. This new implementation is designed for a particular usage scenario with the intention of trading space for speed and improving performance of some reliable UDP code. Over the last four entries I've implemented various parts of the timer wheel and adjusted the test code so that I could reuse the tests that I already had for the other implementations with my timer wheel. The tests needed to be tweaked quite a bit to take into account the different behavioural characteristics of the…

Practical Testing: 27 - Fixing things...

| 0 Comments
Previously on "Practical Testing"... To deal with some specific usage scenarios of a piece of general purpose code I'm in the process of implementing a timer wheel that matches the interface to the timer queue that I previously developed in this series of articles. Last time I left myself with a failing test. The problem is that setting a new timer on the timer wheel sets a timer that's relative to the time that timer wheel thinks is 'now' and the timer wheel's view of the current time could be slightly behind reality; see the previous entry for a diagram…
Previously on "Practical Testing"... To deal with some specific usage scenarios of a piece of general purpose code I'm in the process of implementing a timer wheel that matches the interface to the timer queue that I previously developed in this series of articles. The timer wheel trades space for speed and so far the development has gone well as I've been able to use the tests that I had already developed for the previous implementations to guide the new development. By the end of last time we'd got to the point where we had four functions left to implement...…

Practical Testing: 25 - Nothing is free

| 0 Comments
I'm in the process of implementing a timer wheel that matches the interface to the timer queue that I previously developed in this series of articles. The idea being that for certain specific usage scenarios the timer wheel will perform better than the timer queues. Last time I refactored the tests that I was using for the timer queues to remove duplication and I now have a set of failing tests for the new timer wheel. As soon as I started to look at making some of the failing tests pass I realised that having a heap of failing tests…
The most recent articles in the "Practical Testing" series have been discussing the performance of the timer queue that we have built. As I hinted when I first brought up the performance issues, the particular use case that I have which is causing problems might well be more efficiently dealt with using a different (more specialised and less general purpose) design. The timer queue has adequate performance for general purpose use and can handle timers set within a range of 0ms to 49.7 days with a theoretical granularity of 1ms. It achieves this by using a balanced search tree to…
The previous article in the "Practical Testing" series set things up so that we can measure the performance of the code under test with the intention of trying to improve performance for a specific set of use case scenarios. This time around I'll make a few changes which I hope will improve the performance and measure the effects of the changes with the performance tests that I added last time. One of the things that struck me about the code when I was looking at it during my profiling runs for my client is that when using the CThreadedCallbackTimerQueue in…
Back in 2004, I wrote a series of articles called "Practical Testing" where I took a piece of complicated multi-threaded code and wrote tests for it. I then rebuild the code from scratch in a test driven development style to show how writing your tests before your code changes how you design your code. Since the original articles there have been several bug fixes and redesigns all of which have been supported by the original unit tests and many of which have led to the development of more tests. The tests were written for the pretty scalable timer queue implementation…

Practical Testing: 20 - Mind the gap

| 0 Comments
Back in 2004, I wrote a series of articles called "Practical Testing" where I took a piece of complicated multi-threaded code and wrote tests for it. I then rebuild the code from scratch in a test driven development style to show how writing your tests before your code changes how you design your code. Since the original articles there have been several bug fixes and redesigns all of which have been supported by the original unit tests and many of which have led to the development of more tests. But... you need to be aware of the tests that you…
The code in the last two articles in the "Practical Testing" series have contained a considerable amount of duplication. This came about for a couple of reasons. Firstly part 17 was a bit rushed and secondly it was useful to compare the CCallbackTimerQueue implementation with the CCallbackTimerQueueEx implementation. I'm also a firm believer that in this kind of situation it's better to get both sets of code working independently and then refactor to remove any duplication rather than attempting to design a duplicate-free solution from the start. Anyway, this time around we'll remove the duplication by creating a base class…
Back in 2004, I wrote a series of articles called "Practical Testing" where I took a piece of complicated multi-threaded code and wrote tests for it. I then rebuild the code from scratch in a test driven development style to show how writing your tests before your code changes how you design your code. Since then there have been various changes and fixes and redesigns all of which were made considerably easier due to the original tests. There has always been a potential for deadlock when using the timer queue, which is unfortunate but something that you can avoid if…

Practical Testing: 17 - A whole new approach

| 0 Comments
The comments to my last practical testing entry got me thinking. The commenter who had located the bug in part 15, which was fixed in part 16, suggested a new approach to the problem and I've been investigating it. The suggestion is, essentially, to use a timer with a longer range before roll-over rather than GetTickCount() with its 49.7 day roll-over. In Vista and later we could just use GetTickCount64() but on earlier platforms that's not available to us. My commenter's solution was to build a GetTickCount64() on top of GetTickCount() and use that. Given that adjusting the code for…

Practical Testing: 16 - Fixing a timeout bug

| 5 Comments
Back in 2004, I wrote a series of articles called "Practical Testing" where I took a piece of complicated multi-threaded code and wrote tests for it. I then rebuild the code from scratch in a test driven development style to show how writing your tests before your code changes how you design your code. Then, in 2005, I adjusted the code to be more scalable and I showed how the tests that had originally been written helped when code needed to be changed for performance purposes. Finally I uploaded a test utility program that I'd been working on, TickShifter, that…

Latest release of socket server code

| 57 Comments
The latest release of the free version of my asynchronous, windows, IOCP based, socket server framework can now be obtained from here at ServerFramework.com. The latest release is really just a bug fix and compiler compatability release. The code now supports Visual Studio 2005 (as well as VC6, Visual Studio .Net (2002) and Visual Studio 2003). I've fixed the memory leak bugs that were present in the ThreadPoolLargePacketEchoServer sample and worked around the iostream leak that's present in the Visual Studio 2005 version of STL. I've also included a set of build configurations for the basic echo server that builds…

Practical Testing: 15 - Testing payback

| 2 Comments
Last year I wrote a series of articles called "Practical Testing" where I took a piece of complicated multi-threaded code and wrote tests for it. I then rebuild the code from scratch in a test driven development style to show how writing your tests before your code changes how you design your code. The code under test was intended to be very scalable, I use the code to provide light weight asynchronous timers for my socket server framework and the idea is that each connection might have several timers associated with it. In the original introduction I wrote this: "The…
A long time ago, on Practical Testing: I mentioned that there was a small chance that the way that ResetTimer() operated could mean that you could pass in a handle that you no longer owned and affect someone else's timer by mistake; I said it was unlikely to cause problems... In this posting we fix this problem and in the process show how TDD builds up a set of tests that can support you during redesign...…

Practical Testing: 13 - Missing functionality

| 0 Comments
Previously, on Practical Testing: we added a multi-threaded version of our timer queue that manages timeouts automatically. This time we'll integrate our new timer queue into an application that uses the old version of the code and, along the way, discover some functionality that the original version supports but that the new version currently doesn't.…

Practical Testing: 12 - Threading is orthogonal

| 0 Comments
Previously, on Practical Testing: we finished our reworking on the code we were left with a simpler timer queue that passed all of our tests, but was single threaded and needed manual intervention from client code to manage timeouts. Today we'll add back the multi-threaded functionality so that the queue manages timeouts automatically.…
Previously, on Practical Testing: having decided to rework the code from scratch in TDD style we fixed the tick count bug for the second time - this time the solution was cleaner and simpler. At the end of that episode we were left with a failing test. The test was for multiple timers and it failed because our TDD route was taking a 'simplest thing that could possibly work' approach and that design only supported a single timer. Today we'll fix that problem by moving nearer to a real world solution.…
Previously, on Practical Testing: Having bolted on some tests to an existing piece of code we're now doing some "agressive refactoring" ;) and rewriting the code from scratch using the testing ideas we developed earlier. The whole point of this exercise was to fix a known bug, we did that in the existing code here, now we have a test that forces us to address the issue in the new code.…
Previously, on Practical Testing: we fought through the pain of writing tests for hard to test code and then we decided to see what it could have been like if we'd developed the code test first... Now we'll add some more tests and some more code, still keeping it all nice and simple...…
I've been writing some blog entries about a piece of code from my 'back catalogue' that didn't have tests and that had a known bug that was reasonably hard to test for. Right at the start I commented that the code was a tad over complicated due to the way it had been developed using HITIW (Hack it till it works). The complexity in the code itself made writing tests for it harder than it should have been and, well, I wouldn't write code like that these days (honest). So, here we are in part 8 and I'm about to…
Previously on Practical Testing: After far too much work we finally got to the point where we had a test for the tick count wrap bug. Now that we have a failing test we can fix the bug.…

Practical Testing: 6 - Tests refactored

| 0 Comments
Previously on Practical Testing: The last entry ended with us having two tests, both of which were in need to a good refactoring. The second test had uncovered an unexpected bug... This time around we'll refactor the tests, fix the bug and finally write the test for the tick count wrap bug...…

Practical Testing: 4 - Taking control of time

| 5 Comments
I'm writing some blog entries that show how to write tests for non trivial pieces of code. This is part 4.…
I'm writing some blog entries that show how to write tests for non trivial pieces of code. This is part 3.…

Practical Testing: 2 - The first test

| 0 Comments
I'm writing some blog entries that show how to write tests for non trivial pieces of code. This is part 2.…

Practical Testing: 1 - Introduction

| 2 Comments | 1 TrackBack
I'm writing some blog entries that show how to write tests for non trivial pieces of code. This is part 1.…

Bluetooth sockets

| 436 Comments
This morning I decided to investigate the Windows XP SP1 Bluetooth support. I played with the BluetoothXXXX API and quickly became disapointed. I then moved on to looking at how to access the Bluetooth hardware using Winsock and decided that is a much better route to take...…

More socket server code updates

| 49 Comments | 1 TrackBack
The latest release of the free version of my asynchronous, windows, IOCP based, socket server framework can now be obtained from here at ServerFramework.com. I've updated the code for two more of the socket server articles. More merging, project file updating, and testing... [NOTE: This code leaks when adjusted to build with Visual Studio 2005. This seems to be due to a bug in VS2005's STL. See here for a workaround. I expect to post a fix for this once I've found time to convert the code to build with the new compiler and then tracked down the leak. If…

Socket Server code updates

| 102 Comments
The latest release of the free version of my asynchronous, windows, IOCP based, socket server framework can now be obtained from here at ServerFramework.com. For some time I've been promising to update the socket server articles to use the latest version of my code. Today I finally updated the code for the first article. I'm going to update the article itself soon, but in the meantime I'm posting the new code here. [NOTE: This code leaks when adjusted to build with Visual Studio 2005. This seems to be due to a bug in VS2005's STL. See here for a workaround.…

Using OpenSSL with Asynchronous Sockets

| 25 Comments
OpenSSL is an open source implementation of the SSL and TLS protocols. Unfortunately it doesn't play well with windows style asynchronous sockets. This article - previously published in Windows Developer Magazine and now available on the Dr. Dobbs site - provides a simple connector that enables you to use OpenSSL asynchronously. Note: If you need high performance SSL over TCP/IP then this is available as an optional part of The Server Framework; see here for details.…

Sinking connection points in C++ objects.

| 2 Comments
Sometimes it would be nice to be able to use a simple C++ object as a sink for Connection Point notifications. This article shows you how.…

Designing asynchonous COM components for VB

| 0 Comments
This example COM component provides three COM objects for using the Win32 Mailslot IPC mechanism. The component may be useful if you need to communicate from VB using Mailslots. However, the reason I wrote it was to demonstrate creating a COM component in C++ that integrates well with VB and can fire asynchronous events.…

AVL Tree

| 2 Comments
A "generic" AVL Tree, from the dark days before templates... The code here is some of my first C++. Back in 1991 C++ was still pretty new. Looking back at my early C++ is better than looking back at my early C. At least my early C++ just looked like OKish C with some odd keywords...…

Rooms 1.7

| 0 Comments
In 1989 I taught myself C to write an adventure game, the code's fairly bad, but 10 year's later, the game's still quite cool!…

Java caches in the middle tier

| 5 Comments
A common way to improve the performance of Java code is to cache objects rather than repeatedly create and destroy them. This is especially true when you're writing middle tier servers that service client requests and return results objects. Implementing a flexible caching scheme in Java is relatively easy, but there are a few things to watch for.…

The CORBA Evictor Pattern in Java

| 0 Comments
When a CORBA server allows its clients to create and destroy objects one of the recommended ways to handle the object lifetime issues is using the Evictor Pattern. In The Evictor Pattern we solved the problem for C++ servers, here we do the same for Java servers.…

CORBA - Keep Alive

| 0 Comments
One way of making a reference counted implementation more robust is to run the keep-alive protocol yourself. We demonstrate this option here.…

CORBA - The Evictor Pattern

| 0 Comments
Since CORBA doesn't really support reliable reference counting implementations we'll compare one of the recommended methods of servant life-time management with our reference counted iteration interface.…

CORBA - Iteration

| 0 Comments
A CORBA style method of enumeration can be seen in the iteration interfaces on the CORBA Naming Service. Given the code we've already written for the enumeration interface we can easily implement an iteration interface as well as (or, more likely, instead of).…

CORBA - Enumeration

| 0 Comments
CORBA provides sequences as a way of returning collections of items from an method call. The problem with just using unbounded sequences is that the client has no control over how many items it receives as a result of the call. COM gets around this problem using the IEnum style interfaces that allow a client to control how it accesses the items in a collection.…

CORBA - More Reference Counting

| 0 Comments
Although we managed to develop a working solution in the first CORBA reference counting article the results were ugly and fragile. In this article we attempt to clean things up a little and, in doing so, get intimate with the Portable Object Adapter and its Servant Managers.…

CORBA - Reference Counting

| 0 Comments
We've been developing code on Windows and Unix for quite some time, but most of the distributed component work we've been involved in has been done using COM. That's changing now as clients have more requirements for Unix based component solutions. We're currently evaluating CORBA ORBs and learning how the CORBA way of doing things differs from the COM way. The first difference that we came across was the way that CORBA servers deal with object lifetime issues. Adding reference counting to CORBA objects isn't as easy as it first seems Please note that these articles initially explore COM concepts…

COM+ Administration

| 0 Comments
COM+ applications can be complex to configure and there's no standard way to save that configuration in a form that can be placed under version control. Luckily the COM+ Catalog is accessible by a set of completely scriptable COM objects. These scripts take advantage of this to provide some functionality that should really come as standard.…

OLEDB - Disconnected Recordsets

| 0 Comments
If you are going to use the client cursor engine then often it's a good idea to disconnect your recordset...…

MFC - Include/Exclude list boxes

| 0 Comments
How to package lots of standard functionality into a CListBox derived class.…

OLEDB - Client Cursor Engine updates

| 0 Comments
Making the ADO Client Cursor Engine believe that your rowset is updateable involves jumping through a few extra hoops...…

OLEDB - Updating data through an ADO recordset

| 0 Comments
The ATL OLE DB Provider templates only seem to support read-only rowsets, and making them support updating of data isn't as easy as you'd expect!…

OLEDB - IRowsetLocate and Bookmarks

| 0 Comments
Adding bookmark functionality is relatively easy and it enables our ADO recordset to be used with a greater number of data bound controls.…

OLEDB - Custom Rowsets

| 0 Comments
The ATL OLE DB Provider templates appear to rely on the fact that your data is kept in a simple array, but that's not really the case at all!…

OLEDB - Objects via ADO

| 0 Comments
ADO seems to be the ideal way to expose tabular data from your own COM objects and the ATL OLE DB Provider templates can help!…

MFC - Templates

| 0 Comments
Templates are a great way of reusing code, unfortunately MFC makes it hard to write MFC friendly template classes...…

IEnumXXXX

| 0 Comments
COM objects generally provide access to sequences using an IEnumXXXX style interface, this class wraps that with an STL style iterator…
« Sound and Vision | Source Code Archives | Testing »

About this Archive

This page is an archive of all entries in the Source Code category.

Sound and Vision is the previous category.

Testing is the next category.

I usually write about C++ development on Windows platforms, but I often ramble on about other less technical stuff...

Find recent content on the main index or look in the archives to find all content.

I have other blogs...

Subscribe to feed The Server Framework - high performance server development
Subscribe to feed Lock Explorer - deadlock detection and multi-threaded performance tools
Subscribe to feed l'Hexapod - embedded electronics and robotics
Subscribe to feed MegèveSki - skiing