Skip to content

Instantly share code, notes, and snippets.

View grantrostig's full-sized avatar
💭
C++, AI/ML, ChatBots

Grant Rostig grantrostig

💭
C++, AI/ML, ChatBots
View GitHub Profile

Introduction

Over time I come across lots of useful resources but then quickly forget about them. What a shame. So I have decided to put it all together in this page. Hopefully this page will come in handy one day. Will populate this page from time to time.

Dictionary type web / app

AI / Machine Learning / Deep Learning

/**
* Awesome website
* @author YOUR_NAME_HERE
* @version 0.1
*/
/* ============================ RESET ============================ */
/* ===== Eric Meyer Reset ===== */

C++: Stateless vs. Stateful Allocators

Categorizing Allocators

All standard C++ library conforming allocators have to support the minimal interface requirements. Beyond these requirements, some examples of fully defined allocators are LLVM's latest standard C++ library implementation of std::allocator, and a custom allocator I've written called ThreadLocalAllocator. These are both examples of what's been categorized as "stateless" allocators. Alternatively, allocators can be "stateful".

C++: Stateless vs. Stateful Allocators

Categorizing Allocators

All standard C++ library conforming allocators have to support the minimal interface requirements. Beyond these requirements, some examples of fully defined allocators are LLVM's latest standard C++ library implementation of std::allocator, and a custom allocator I've written called ThreadLocalAllocator. These are both examples of what's been categorized as "stateless" allocators. Alternatively, allocators can be "stateful".

@grantrostig
grantrostig / min_cpp_allocator.md
Created August 22, 2023 23:56 — forked from louis-langholtz/min_cpp_allocator.md
Minimal C++ Allocator

C++: Minimal Allocator

From item 11 of section 16.5.3.5 Cpp17Allocator requirements of n4861.pdf:

"The following is an allocator class template supporting the minimal interface...":

template<class Tp>
struct SimpleAllocator {
 typedef Tp value_type;
@grantrostig
grantrostig / cpp-thread-safe-initialization.md
Created November 26, 2023 06:11 — forked from louis-langholtz/cpp-thread-safe-initialization.md
C++ Requires Thread Safe Initialization of Block-Scope Variables With Static or Thread Storage Duration

C++: Thread Safe Initialization Requirements

Seems like this has come up for me enough in discussing C++ with others, that it might help to put together the information in this gist.

Standard C++ has since C++11 required that block-scope variables with static or thread storage duration get initialized in a thread safe way. Besides there being a StackOverflow answer - to a related question - showing some example assembly for C++11 that includes thread safe guards, there's also the C++ standard documents themselves.

What follows is the specific requirement by versions of the standard.

C++03