HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
buffer_deleter.h
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License.
3 
4 #pragma once
5 
7 
8 namespace onnxruntime {
9 
10 // TODO: Do we need this class or is IAllocator::MakeUniquePtr sufficient/better
12  public:
13  BufferDeleter() = default;
14  explicit BufferDeleter(AllocatorPtr alloc)
15  : alloc_(std::move(alloc)) {}
16 
17  void operator()(void* p) const {
18  if (alloc_)
19  alloc_->Free(p);
20  }
21 
22  private:
23  // TODO: we may need consider the lifetime of alloc carefully
24  // The alloc_ here is the allocator that used to allocate the buffer
25  // And need go with the unique_ptr together. If it is using our internal
26  // allocator, it is ok as our allocators are global managed. But if it
27  // is provide by user, user need to be very careful about it.
28  // A weak_ptr may be a choice to reduce the impact, but that require to
29  // change our current allocator mgr to use shared_ptr. Will revisit it
30  // later.
31  AllocatorPtr alloc_{nullptr};
32 };
33 
34 using BufferUniquePtr = std::unique_ptr<void, BufferDeleter>;
35 using BufferNakedPtr = void*;
36 } // namespace onnxruntime
void operator()(void *p) const
std::unique_ptr< void, BufferDeleter > BufferUniquePtr
void * BufferNakedPtr
std::shared_ptr< IAllocator > AllocatorPtr
Definition: allocator.h:261
BufferDeleter(AllocatorPtr alloc)