18 #ifndef ION_BASE_DATACONTAINER_H_
19 #define ION_BASE_DATACONTAINER_H_
28 #include "base/integral_types.h"
29 #include "base/macros.h"
77 typedef std::function<void(void* data_to_delete)>
Deleter;
83 T* data =
reinterpret_cast<T*
>(data_to_delete);
88 T* data =
reinterpret_cast<T*
>(data_to_delete);
103 template <
typename T>
105 return reinterpret_cast<const T*
>(GetDataPtr());
110 return reinterpret_cast<const void*
>(GetDataPtr());
114 template <
typename T>
116 T* data =
reinterpret_cast<T*
>(GetDataPtr());
120 LOG(
ERROR) <<
"GetMutableData() called on NULL (or wiped) DataContainer. "
121 "The contents of the original buffer will not be returned "
122 "and any data in GPU memory will likely be cleared. This "
123 "is probably not what you want.";
128 template <
typename T>
130 T* data,
const Deleter& data_deleter,
bool is_wipeable,
132 if (data_deleter && !AddOrRemoveDataFromCheck(data,
true))
135 Allocate(0, data_deleter, is_wipeable, container_allocator);
136 container->data_ = data;
141 template <
typename T>
143 const T* data,
size_t count,
bool is_wipeable,
146 Allocate(0,
kNullFunction, is_wipeable, container_and_data_allocator);
150 container->data_allocator_ =
157 container->deleter_ =
159 std::placeholders::_1);
164 memcpy(container->data_, data,
sizeof(
T) * count);
169 template <
typename T>
171 size_t count,
const T* data,
const AllocatorPtr& container_allocator) {
175 false, container_allocator);
176 uint8* ptr =
reinterpret_cast<uint8*
>(container) +
sizeof(
DataContainer);
178 container->data_ = ptr + 16 - (
reinterpret_cast<size_t>(ptr) % 16);
181 memcpy(container->data_, data,
sizeof(
T) * count);
202 static DataContainer* Allocate(
size_t extra_bytes,
const Deleter& deleter,
210 static bool AddOrRemoveDataFromCheck(
void* data,
bool is_add);
213 virtual void InternalWipeData();
216 virtual void* GetDataPtr()
const {
return data_; }
230 DISALLOW_IMPLICIT_CONSTRUCTORS(DataContainer);
236 #endif // ION_BASE_DATACONTAINER_H_
kShortTerm is used for objects that are very transient in nature, such as scratch memory used to comp...
#define LOG(severity)
Logs the streamed message unconditionally with a severity of severity.
A Notifier both sends notifications to and receives notifications from other Notifiers.
base::WeakReferentPtr< DataContainer > DataContainerWeakPtr
virtual const AllocatorPtr & GetAllocatorForLifetime(AllocationLifetime lifetime) const
Returns the correct Allocator to use to allocate memory with a specific lifetime. ...
static DataContainerPtr CreateOverAllocated(size_t count, const T *data, const AllocatorPtr &container_allocator)
See class comment for documentation.
static void PointerDeleter(void *data_to_delete)
The DataContainer class encapsulates arbitrary user data passed to Ion.
T * Get() const
Returns a raw pointer to the instance, which may be NULL.
std::function< void(void *data_to_delete)> Deleter
Generic delete function.
static void ArrayDeleter(void *data_to_delete)
Generic deleters that perform the most common deletion operations.
static void AllocatorDeleter(AllocatorPtr allocator, void *data_to_delete)
A deleter for data allocated by an Allocator.
const void * GetData() const
Default GetData() returns a const void pointer.
Copyright 2016 Google Inc.
void DeallocateMemory(void *p)
Deallocates a previously-allocated memory block.
#define kNullFunction
Copyright 2016 Google Inc.
void * AllocateMemory(size_t size)
Allocates memory of the given size.
static DataContainerPtr CreateAndCopy(const T *data, size_t count, bool is_wipeable, const AllocatorPtr &container_and_data_allocator)
See class comment for documentation.
base::ReferentPtr< DataContainer >::Type DataContainerPtr
const AllocatorPtr & GetAllocator() const
Returns the Allocator that was used for the instance.
A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting...
static DataContainerPtr Create(T *data, const Deleter &data_deleter, bool is_wipeable, const AllocatorPtr &container_allocator)
See class comment for documentation.
T * GetMutableData() const
Returns a non-const data pointer.
const T * GetData() const
Returns a const data pointer.
A WeakReferentPtr is a weak reference to an instance of some class derived from Referent.
bool IsWipeable() const
Returns the is_wipeable setting passed to the constructor.
static const AllocatorPtr & GetDefaultAllocatorForLifetime(AllocationLifetime lifetime)