Open3D (C++ API)  0.18.0+252c867
Blob.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <cstddef>
11 #include <functional>
12 #include <iostream>
13 #include <string>
14 
15 #include "open3d/core/Device.h"
17 
18 namespace open3d {
19 namespace core {
20 
38 class Blob {
39 public:
44  Blob(int64_t byte_size, const Device& device)
45  : deleter_(nullptr),
46  data_ptr_(MemoryManager::Malloc(byte_size, device)),
47  device_(device) {}
48 
56  Blob(const Device& device,
57  void* data_ptr,
58  const std::function<void(void*)>& deleter)
59  : deleter_(deleter), data_ptr_(data_ptr), device_(device) {}
60 
61  ~Blob() {
62  if (deleter_) {
63  // Our custom deleter's void* argument is not used. The deleter
64  // function itself shall handle destruction without the argument.
65  // The void(void*) signature is kept to be consistent with DLPack's
66  // deleter.
67  deleter_(nullptr);
68  } else {
70  }
71  };
72 
73  Device GetDevice() const { return device_; }
74 
75  void* GetDataPtr() { return data_ptr_; }
76 
77  const void* GetDataPtr() const { return data_ptr_; }
78 
79 protected:
81  std::function<void(void*)> deleter_ = nullptr;
82 
84  void* data_ptr_ = nullptr;
85 
88 };
89 
90 } // namespace core
91 } // namespace open3d
Definition: Blob.h:38
std::function< void(void *)> deleter_
For externally managed memory, deleter != nullptr.
Definition: Blob.h:81
Device device_
Device context for the blob.
Definition: Blob.h:87
void * data_ptr_
Device data pointer.
Definition: Blob.h:84
Device GetDevice() const
Definition: Blob.h:73
Blob(const Device &device, void *data_ptr, const std::function< void(void *)> &deleter)
Definition: Blob.h:56
const void * GetDataPtr() const
Definition: Blob.h:77
Blob(int64_t byte_size, const Device &device)
Definition: Blob.h:44
void * GetDataPtr()
Definition: Blob.h:75
~Blob()
Definition: Blob.h:61
Definition: Device.h:18
Definition: MemoryManager.h:34
static void Free(void *ptr, const Device &device)
Frees previously allocated memory at address ptr on device device.
Definition: MemoryManager.cpp:28
const char const char value recording_handle imu_sample void
Definition: K4aPlugin.cpp:250
Definition: PinholeCameraIntrinsic.cpp:16