Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
Globals.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4#include "../Foundation/PrimitiveTypes.h"
5#include "../Memory/Memory.h"
6namespace SC
7{
8struct SC_MEMORY_EXPORT GlobalSettings;
9struct SC_MEMORY_EXPORT Globals;
10struct MemoryAllocator;
11} // namespace SC
14
20
38{
39 enum Type
40 {
41 Global = 0,
43 };
44 MemoryAllocator& allocator;
45
46 Globals(MemoryAllocator& allocator) : allocator(allocator) {}
47
50 static void init(Type type, GlobalSettings settings = {});
51
54 static Globals* push(Type type, Globals& globals);
55
58 static Globals* pop(Type type);
59
61 static Globals& get(Type type);
62
63 private:
64 Globals* prev = nullptr; // Pointer to previous Globals to restore on ::pop()
65 struct Internal;
66};
67
Settings to initialize Globals.
Definition Globals.h:17
size_t ownershipTrackingBytes
Memory to allocate for ownership tracking.
Definition Globals.h:18
Customizable thread-local and global variables for memory handling.
Definition Globals.h:38
static Globals * push(Type type, Globals &globals)
Sets Globals as current, saving previous one.
static Globals & get(Type type)
Obtains current set of Globals.
static Globals * pop(Type type)
Restores Globals previously replaced by a push.
Type
Definition Globals.h:40
@ Global
Shared globals (NOT thread-safe)
Definition Globals.h:41
@ ThreadLocal
Thread-specific globals (separate copy for each thread)
Definition Globals.h:42
static void init(Type type, GlobalSettings settings={})
Initialized Globals for current thread.
Customizable functions to allocate, reallocate and deallocate memory.
Definition Memory.h:42