Concurrent wrapper that gives each thread its own sub‐allocator.

Synopsis

Declared in <llvm/Support/PerThreadBumpPtrAllocator.h>

template<typename AllocatorTy>
class PerThreadAllocator
    : public AllocatorBase<PerThreadAllocator<AllocatorTy>>

Description

PerThreadAllocator wraps a thread‐unsafe allocator (e.g. BumpPtrAllocator) for lock‐free concurrent allocation: each thread receives its own sub‐allocator on first allocation, and the PerThreadAllocator owns all sub‐allocators. Recommended to used with the thread pool in Parallel.h even if there is no dependency on it.

Base Classes

Name

Description

AllocatorBase<PerThreadAllocator<AllocatorTy>>

CRTP base class providing obvious overloads for the core Allocate() methods of LLVM‐style allocators.

Member Functions

Name

Description

PerThreadAllocator [constructor]

Construct an empty per‐thread allocator with a fresh instance id.

Allocate

Allocate overloads

Deallocate

Deallocate overloads

PrintStats

Print statistic for each allocator.

Reset

Reset state of allocators.

getNumberOfAllocators

Return the number of sub‐allocators, i.e. threads that have allocated.

getThreadLocalAllocator

Return the calling thread's sub‐allocator, creating it on first use.

getTotalMemory

Return total memory size used by all allocators.

setRedZoneSize

Set red zone for all allocators.

Using Declarations

Name

Description

Allocate

Bring AllocatorBase typed Allocate overloads into scope.

Deallocate

Bring AllocatorBase typed Deallocate overloads into scope.

Protected Data Members

Name

Description

Id

Process‐unique id indexing this instance in each thread's cache.

S

Shared mutex and owned list of per‐thread sub‐allocators.

Created with MrDocs