Skip to content

hosseinmoein/Cougar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub C++20 Maintenance

Allocator Cougar

This repo includes several STL conformant allocators. There are two categories of allocators here:

  1. Stack or Static based fixed size allocators. In this category you pre-allocate a fixed size memory block either on the stack or statically. So you can have STL containers that are based on stack memory, for example. One of the side effects of these allocators is to overcome deficiencies in containers like maps and lists where their memory by default is not cache-friendly.
  2. Custom Aligned allocator. This allocator allows you to allocate memory on a custom boundary. This way you can take advantage of SIMD instructions and techniques.

Please see the tester file for code samples.

This is the complete list of allocators in this repo:

// An allocator that allows you to allocate memory for type T on boundary AS.
// The default boundary is system default for type T.
template<typename T, std::size_t AS = 0>
AlignedAllocator
// This allocator pre-allocates memory for MAX_SIZE * sizeof(T) bytes statically.
// It uses best-fit algorithm to find space. Best-fit is a bit slower,
// but it causes considerably less fragmentations
template<typename T, std::size_t MAX_SIZE>
StaticBestFitAllocator
// This allocator pre-allocates memory for MAX_SIZE * sizeof(T) bytes on the stack.
// It uses best-fit algorithm to find space. Best-fit is a bit slower,
// but it causes considerably less fragmentations
template<typename T, std::size_t MAX_SIZE>
StackBestFitAllocator
// This allocator pre-allocates memory for MAX_SIZE * sizeof(T) bytes statically.
// It uses first-fit algorithm to find space. First-fit is faster,
// but it causes more fragmentations
template<typename T, std::size_t MAX_SIZE>
StaticFirstFitAllocator
// This allocator pre-allocates memory for MAX_SIZE * sizeof(T) bytes on the stack.
// It uses first-fit algorithm to find space. First-fit is faster,
// but it causes more fragmentations
template<typename T, std::size_t MAX_SIZE>
StackFirstFitAllocator