Class Allocator

Class Documentation

class Allocator

Allocator defined a memory pool for malloc memory and free memory dynamically.

Public Functions

virtual ~Allocator() = default

Destructor of MindSpore Allocator.

virtual void *Malloc(size_t size) = 0

Method to request memory.

Parameters

size[in] Define the memory size to request.

inline virtual void *Malloc(size_t weight, size_t height, DataType type)

Method to request memory.

Parameters
  • weight[in] Defines the width of memory to request

  • height[in] Defines the height of memory to request

  • type[in] Defines the data type of memory to request

virtual void Free(void *ptr) = 0

Method to free memory.

Parameters

ptr[in] Define the pointer of a certain memory.

virtual int RefCount(void *ptr) = 0

Reference count of a certain memory.

Parameters

ptr[in] Define the pointer of a certain memory.

Returns

Reference count of a certain memory currently.

virtual int SetRefCount(void *ptr, int ref_count) = 0

Set reference count of a certain memory.

Parameters
  • ptr[in] Define the pointer of a certain memory.

  • ref_count[in] Define the reference count to set.

Returns

Reference count of a certain memory after setting.

virtual int DecRefCount(void *ptr, int ref_count) = 0

Decrease the reference count of a certain memory.

Parameters
  • ptr[in] Define the pointer of a certain memory.

  • ref_count[in] Define the reference count to reduce.

Returns

Reference count of a certain memory after decreating.

virtual int IncRefCount(void *ptr, int ref_count) = 0

Increase the reference count of a certain memory.

Parameters
  • ptr[in] Define the pointer of a certain memory.

  • ref_count[in] Define the reference count to increase.

Returns

Reference count of a certain memory after increasing.

inline virtual void *Prepare(void *ptr)

Prepare a certain memory.

Parameters

ptr[in] Define the pointer of a certain memory to prepare.

Returns

Pointer of ready memory.

Public Static Functions

static std::shared_ptr<Allocator> Create()

Static method to create an allocator.

Returns

Smart pointer of an allocator.