Class ov::Allocator

class Allocator

Wraps allocator implementation to provide safe way to store allocater loaded from shared library And constructs default based on new delete c++ calls allocator if created without parameters Accepts any std::pmr::memory_resource like allocator.

Public Functions

~Allocator()

Destructor preserves unloading order of implementation object and reference to library.

Allocator()

Default constructor.

Allocator(const Allocator &other) = default

Default copy constructor.

Parameters

other – other Allocator object

Allocator &operator=(const Allocator &other) = default

Default copy assignment operator.

Parameters

other – other Allocator object

Returns

reference to the current object

Allocator(Allocator &&other) = default

Default move constructor.

Parameters

other – other Allocator object

Allocator &operator=(Allocator &&other) = default

Default move assignment operator.

Parameters

other – other Allocator object

Returns

reference to the current object

OPENVINO_SUPPRESS_DEPRECATED_START Allocator(const AllocatorImpl::Ptr &impl)

Constructs Allocator from the initialized std::shared_ptr.

Parameters

impl – Initialized shared pointer

template<typename A, typename std::enable_if<!std::is_convertible<A, AllocatorImpl::Ptr>::value && !std::is_same<typename std::decay<A>::type, Allocator>::value && !std::is_abstract<typename std::decay<A>::type>::value && !std::is_convertible<typename std::decay<A>::type, std::shared_ptr<Base>>::value, bool>::type = true>
inline Allocator(A &&a)

Initialize allocator using any allocator like object.

Template Parameters

A – Type of allocator

Parameters

a – allocator object

OPENVINO_SUPPRESS_DEPRECATED_END void * allocate (const size_t bytes, const size_t alignment=alignof(max_align_t))

Allocates memory.

Parameters
  • bytes – The size in bytes at least to allocate

  • alignment – The alignment of storage

Throws

Exception – if specified size and alignment is not supported

Returns

Handle to the allocated resource

void deallocate(void *ptr, const size_t bytes = 0, const size_t alignment = alignof(max_align_t))

Releases the handle and all associated memory resources which invalidates the handle.

Parameters
  • ptr – The handle to free

  • bytes – The size in bytes that was passed into allocate() method

  • alignment – The alignment of storage that was passed into allocate() method

bool operator==(const Allocator &other) const

Compares with other Allocator.

Parameters

other – Other instance of allocator

Returns

true if and only if memory allocated from one Allocator can be deallocated from the other and vice versa

bool operator!() const noexcept

Checks if current Allocator object is not initialized.

Returns

true if current Allocator object is not initialized, false - otherwise

explicit operator bool() const noexcept

Checks if current Allocator object is initialized.

Returns

true if current Allocator object is initialized, false - otherwise