ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
allocator.h
Go to the documentation of this file.
1#ifndef BASE_CORE_ALLOCATOR_H_
2#define BASE_CORE_ALLOCATOR_H_
3
5
6namespace base {
7namespace core {
17class Allocator {
18 public:
26 virtual void* allocate(size_t size) = 0;
27
36 virtual void* allocate(size_t size, size_t alignment) = 0;
37
43 virtual void free(void* ptr) = 0;
44
51 virtual size_t AllocatedSize(void* ptr) {
52 return allocated_size_;
53 }
54
61
62 virtual ~Allocator() = default;
63
64 protected:
68 size_t allocated_size_ = 0;
69};
70
71} // namespace core
72} // namespace base
73
74#endif // BASE_CORE_ALLOCATOR_H_
An abstract base class for memory allocators.
Definition allocator.h:17
virtual container::DeviceType GetDeviceType()=0
Get the type of memory used by the TensorBuffer.
size_t allocated_size_
The total number of bytes allocated by this allocator.
Definition allocator.h:68
virtual void * allocate(size_t size, size_t alignment)=0
Allocate a block of memory with the given size and alignment.
virtual size_t AllocatedSize(void *ptr)
Get the allocated size of a given pointer.
Definition allocator.h:51
virtual ~Allocator()=default
virtual void * allocate(size_t size)=0
Allocate a block of memory with the given size and default alignment.
virtual void free(void *ptr)=0
Free a block of memory that was previously allocated by this allocator.
Definition allocator.h:6
DeviceType
The type of memory used by an allocator.
Definition tensor_types.h:73
This file contains the definition of the DataType enum class.