Showing posts fromc by-example

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 consisten

Read More

Memory Resizing

So I never really considered why the resize of vector used a constant expansion of 1.5 or 2 (in some popular implementations). That was until I did my previous article Xseries ["Vector"]({{config.sit

Read 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 a

Read More

Smart-Pointer - Shared Pointer

So in [the previous article](https://lokiastari.com/posts/Smart-Pointer-UniquePointer) I covered a basic `unique` pointer where the smart pointer retained sole ownership of the pointer. The other comm

Read More

Smart-Pointer - Unique Pointer

On [codereview.stackexchange.com](https://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

Read 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 pro

Read More

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 commu

Read More

Socket Read/Write

## Checking read/write success 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

Read 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

Read 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

Read 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`. Unl

Read 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 manuall

Read 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 cons

Read More