This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstdint> | |
#include <cassert> | |
#include <xmmintrin.h> | |
/////////////////////////////////////////////////////////////////////////////// | |
namespace detail | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cassert> | |
#include <cstdint> | |
#include <cstdarg> | |
#include <cstdio> | |
#include <cmath> | |
#define WIN32_LEAN_AND_MEAN | |
#include <Windows.h> | |
#include <intrin.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Mostly complete and usable C++ version of Rust's Option<T> and Result<T,E> using only standard C++14, for fun. | |
// This code is in the public domain. | |
/////////////////////////////////////////////////////////////////////////////// | |
// Option.hpp | |
/////////////////////////////////////////////////////////////////////////////// | |
#pragma once | |
// ---------------------------------------------------------------------------- | |
// Includes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---------------------------------------------------------------------------- | |
// c++ -std=c++11 -Wall -Wextra -Wshadow -Wunused -pedantic -fsanitize=address -fno-omit-frame-pointer asan_guarded_allocator.cpp | |
#include <cassert> | |
#include <cstdio> | |
#include <cstdint> | |
#include <cstdlib> | |
#include <unordered_map> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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. | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
// ======================================================== | |
#include <algorithm> | |
#include <array> | |
#include <cstddef> | |
#include <cstdint> | |
#include <cstring> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---------------------------------------------------------------------------- | |
// 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. | |
// ---------------------------------------------------------------------------- |
NewerOlder