Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.16.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Blob.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018-2021 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <cstddef>
30 #include <functional>
31 #include <iostream>
32 #include <string>
33 
34 #include "open3d/core/Device.h"
36 
37 namespace open3d {
38 namespace core {
39 
57 class Blob {
58 public:
63  Blob(int64_t byte_size, const Device& device)
64  : deleter_(nullptr),
65  data_ptr_(MemoryManager::Malloc(byte_size, device)),
66  device_(device) {}
67 
75  Blob(const Device& device,
76  void* data_ptr,
77  const std::function<void(void*)>& deleter)
78  : deleter_(deleter), data_ptr_(data_ptr), device_(device) {}
79 
80  ~Blob() {
81  if (deleter_) {
82  // Our custom deleter's void* argument is not used. The deleter
83  // function itself shall handle destruction without the argument.
84  // The void(void*) signature is kept to be consistent with DLPack's
85  // deleter.
86  deleter_(nullptr);
87  } else {
89  }
90  };
91 
92  Device GetDevice() const { return device_; }
93 
94  void* GetDataPtr() { return data_ptr_; }
95 
96  const void* GetDataPtr() const { return data_ptr_; }
97 
98 protected:
100  std::function<void(void*)> deleter_ = nullptr;
101 
103  void* data_ptr_ = nullptr;
104 
107 };
108 
109 } // namespace core
110 } // namespace open3d
std::function< void(void *)> deleter_
For externally managed memory, deleter != nullptr.
Definition: Blob.h:100
Device device_
Device context for the blob.
Definition: Blob.h:106
Blob(const Device &device, void *data_ptr, const std::function< void(void *)> &deleter)
Definition: Blob.h:75
static void Free(void *ptr, const Device &device)
Frees previously allocated memory at address ptr on device device.
Definition: MemoryManager.cpp:47
Device GetDevice() const
Definition: Blob.h:92
Definition: Blob.h:57
Definition: Device.h:37
Definition: MemoryManager.h:53
void * data_ptr_
Device data pointer.
Definition: Blob.h:103
~Blob()
Definition: Blob.h:80
Definition: PinholeCameraIntrinsic.cpp:35
const void * GetDataPtr() const
Definition: Blob.h:96
void * GetDataPtr()
Definition: Blob.h:94
Blob(int64_t byte_size, const Device &device)
Definition: Blob.h:63