Socket Protocols

In the previous articles I have used a very simplistic protocol. In real world situations this simple protocol is not sufficient. To provide a more robust connection between client and server a communications protocol is required so that we can vali…more

C++ Wrapper for Socket

The last two articles examined the "C Socket" interface that is provided by OS. In this article I wrap this functionality in a very simple C++ class to provide guaranteed closing and apply a consistent exception strategy. The first step is to rewrite…more

The read() and write() command can fail in a couple of ways but can also succeed without reading/writing all the data, a common mistake is not to check the amount of data read/written from/to a stream. Interesting…more

Socket Programming in C

Building a simple client/server application is the common first internet based applications developers attempt. These applications are built on top of the socket communication library, but socket programming in C++ is not obvious as there are no sta…more

Memory Resizing

So I never really considered why the resize of vector used a constant…more

Vector - The Other Stuff

So the C++ standard specifies a set of requirements for containers. Very few requirements are specified in terms of containers so adhering to these exactly is not required (unless you want to be considered for the standard). But they provide an insi…more

Vector - Simple Optimizations

So now that we have used std::is_nothrow_move_constructible we can also look at a couple of other types available in the template utility library.

Optimized Destruction

Since we have to manually call the destructor on all objects in the contai…more

Vector - Resize

Because resizing a vector is expensive; the std::vector class uses exponential growth to minimize the number of times that the vector is resized: a technique we replicate in this version. But every now and then you still need to resize the internal…more

Vector - Resource Management Copy Swap

In the previous article I went over basic allocation for a Vector like class. In this article I want to put some detail around the copy assignment operator and resizing the underlying Vector. Unlike the other methods previously discussed these m…more

Vector - Resource Management Allocation

A lot of new developers to C++ attempt to build a Vector like container as a learning processes. Getting a simple version of this working for POD types (like int) is not that complicated. The next step in getting this working for arbitrary data ty…more

Smart-Pointer - Constructors

In this article we examine constructors that are often missed or overlooked. This article looks at the use cases for these constructors and explains why the added functionality provides a meaningful addition in relation to smart pointers.

Smart-Pointer - Shared Pointer

So in the previous article I covered a basic unique pointer where the smart pointer retained sole ownership of the pointer. The other common smart pointer we encounter …more

Smart-Pointer - Unique Pointer

On codereview.stackexchange.com in the C++ tag it seems that it is a write of passage to implement your own version of a smart pointer. A quick search brings up the following:

• 02/Sep/2011 - [shared_ptr imple…more

Nearly New Year/New Resolution

New Year/New Resolution

They say you can only get better at something by doing it.

I want to get better at writing articles about what I do so I better keep trying. Reading the articles I wrote last year (with the hindsight of a year) it seems my…more

Control Flow

So far we have demonstrated basic programs that just do a single task without making any decisions. Most (all but the most trivial) programming languages provide constructs for decision making (Conditional Branching).

C++ provides two forms of bran…more

Switching to OctoPress

Switching to OctoPress and Github

I have not blogged much, until recently, so I am not an HTML/CSS/Javascript expert. Thus layout, or layout during writing an article, is not of supreme importance for me. I expect the framework to handle that al…more

Functions

Usage

All C++ applications must have at least one function; this is called main(). Additionally, you can have user defined functions that encapsulate individual tasks, thus allowing the code to be cleaner and easier to read. Therefore, this is…more

Variables

Variables

In most programming languages you have the concept of variables. These are simply named objects that hold a value (more formerly refereed to as state). By manipulating a variable you manipulate the state of the object that the variable…more

Common Mistakes

1: using namespace

Every new developer that comes to C++ always starts writing code like this:

myfirstprog.cpp

#include <iostream>

using namespace std;

It seems reasonable and every book on learning C++ out there perpetrates the sam…more

Want to set up WordPress to write about Programming

Setting up WordPress to display syntax highlighted code was a struggle due to different plugins that don’t all seem to work together, the different types of editor, etc. I don’t want to learn all about WordPress. I just want to write some simple art…more