Open3D (C++ API)  0.12.0
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 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 <iostream>
31 #include <string>
32 
33 #include "open3d/core/Device.h"
35 
36 namespace open3d {
37 namespace core {
38 
56 class Blob {
57 public:
62  Blob(int64_t byte_size, const Device& device)
63  : deleter_(nullptr),
64  data_ptr_(MemoryManager::Malloc(byte_size, device)),
65  device_(device) {}
66 
74  Blob(const Device& device,
75  void* data_ptr,
76  const std::function<void(void*)>& deleter)
77  : deleter_(deleter), data_ptr_(data_ptr), device_(device) {}
78 
79  ~Blob() {
80  if (deleter_) {
81  // Our custom deleter's void* argument is not used. The deleter
82  // function itself shall handle destruction without the argument.
83  // The void(void*) signature is kept to be consistent with DLPack's
84  // deleter.
85  deleter_(nullptr);
86  } else {
88  }
89  };
90 
91  Device GetDevice() const { return device_; }
92 
93  void* GetDataPtr() { return data_ptr_; }
94 
95  const void* GetDataPtr() const { return data_ptr_; }
96 
97 protected:
99  std::function<void(void*)> deleter_ = nullptr;
100 
102  void* data_ptr_ = nullptr;
103 
106 };
107 
108 } // namespace core
109 } // namespace open3d
std::function< void(void *)> deleter_
For externally managed memory, deleter != nullptr.
Definition: Blob.h:99
Device device_
Device context for the blob.
Definition: Blob.h:105
Blob(const Device &device, void *data_ptr, const std::function< void(void *)> &deleter)
Definition: Blob.h:74
static void Free(void *ptr, const Device &device)
Definition: MemoryManager.cpp:44
Device GetDevice() const
Definition: Blob.h:91
Definition: Blob.h:56
Definition: Device.h:39
Definition: MemoryManager.h:42
void * data_ptr_
Device data pointer.
Definition: Blob.h:102
~Blob()
Definition: Blob.h:79
Definition: PinholeCameraIntrinsic.cpp:35
const void * GetDataPtr() const
Definition: Blob.h:95
void * GetDataPtr()
Definition: Blob.h:93
Blob(int64_t byte_size, const Device &device)
Definition: Blob.h:62