View mini_heap_allocator.cpp
//
// General purpose minimal heap allocator.
//
// Keeps a freelist of chunks of arbitrary size. First round of allocations
// will use the whole heap block before it starts going into the freelist.
// Freeing just pushes the block back into the freelist and is constant time.
// Allocating might search the freelist if the whole heap was already allocated
// once.
//
// To reduce fragmentation we could merge free nodes either on free or allocate.
View tiny_allocator.cpp
//
// Simple allocator for small memory blocks (from 1 to 255 bytes).
// It keeps freelists of small blocks, built on top of 8K pages.
// The allocator only grows - empty pages are never freed back
// to the system.
//
// This allocator could easily be made lockless with atomic freelists.
//
#include <cstdint>
View lockless_hash_table.cpp
// License:
// Public Domain. Feel free to copy, distribute, and modify this file as you see fit.
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <array>
#include <atomic>
View in_place_function.hpp
#pragma once
// ============================================================================
// About:
// std::function-like functor that has an inline buffer to store the
// callable object. It is guaranteed to never allocate. If the callable
// is too big, a static_assert is triggered. The size of the functor is
// defined as a template argument, so it can be of any size. It also doesn't
// use C++ exceptions.
//
View simple_heap.hpp
#pragma once
// ========================================================
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <cstring>
View simple_lru_cache.cpp
// ----------------------------------------------------------------------------
// Least Recently Used cache backed by a hash table
// (unprdered_map) and a fixed-size circular queue.
//
// License:
// Public Domain.
// Feel free to copy, distribute, and modify this file as you see fit.
// ----------------------------------------------------------------------------
View stack_machine.cpp
//
// Simple stack-based virtual machine tests.
//
// I use two slightly different strategies to manage the
// interpreter stack: First is using the "naive" approach
// of keeping a stack pointer that is bumped/decremented
// for every instruction that has stack operands. The second
// approach uses a "stack cache" register to cache the
// Top-of-Stack (TOS) value.
//
View atomic_slist_128bits_cas.cpp
// --------------------------------------------------------------------------------------
// Atomic singly-linked intrusive list using 128-bits Compare And Swap (AKA: DCAS).
// Keeps a version counter with the list head to prevent the A-B-A problem.
//
// Based on the implementation found in moodycamel.com:
// http://moodycamel.com/blog/2014/solving-the-aba-problem-for-lock-free-free-lists
//
// My implementation uses raw GCC/Clang atomics intrinsics. While in theory
// std::atomic of a struct of exactly 16 bytes and properly aligned could
View memory_pools.hpp
// ================================================================================================
// -*- C++ -*-
// File: memory_pools.hpp
// Author: Guilherme R. Lampert
// Created on: 08/02/17
//
// About:
// Useful templated memory pools of objects (header only).
// This file provides a DynamicPool and a pair of FixedSizePools,
View data_race_detection.cpp
//
// Simple unique lock guard to detect concurrent access to unsynchronized global data.
//
// This can be a useful tool to debug data races and identify places where a mutex should
// be introduced. Once the race is fixed, you'll likely want to strip out this code...
//
// --------------------------------------------------------
#include <atomic>