46 ResourceDataList resources_;
64 template<
size_t Size,
size_t Alignment>
84 template<
typename T>
T *
add(std::unique_ptr<T> resource);
90 template<
typename T>
T *
add(std::shared_ptr<T> resource);
102 void add(
void *userdata,
void (*
free)(
void *));
118 template<
typename T,
typename... Args>
T &
construct(Args &&...args);
134 static LinearAllocator<> &create_own_allocator_in_buffer(ResourceDataList &r_resources,
137 bool free_on_destruct);
152template<
size_t Size,
size_t Alignment>
160 T *ptr = resource.release();
161 if (ptr ==
nullptr) {
164 this->
add(ptr, [](
void *
data) {
165 T *typed_data =
reinterpret_cast<T *
>(
data);
176 T *ptr = resource.get();
177 this->
add_destruct_call([resource = std::move(resource)]()
mutable { resource.reset(); });
183 T *ptr = resource.release();
184 if (ptr ==
nullptr) {
188 if constexpr (std::is_trivially_destructible_v<T>) {
192 this->
add(ptr, [](
void *
data) {
193 T *typed_data =
reinterpret_cast<T *
>(
data);
202 data.data = userdata;
204 resources_.append(allocator_,
data);
214 void *buffer = allocator_.allocate(
sizeof(Func),
alignof(Func));
215 new (buffer) Func(std::move(func));
216 this->
add(buffer, [](
void *
data) { (*
static_cast<Func *
>(
data))(); });
221 destruct_ptr<T> value_ptr = allocator_.construct<
T>(std::forward<Args>(args)...);
222 T &value_ref = *value_ptr;
223 this->
add(std::move(value_ptr));
229 void *buffer = allocator_.allocate(type);
bool is_trivially_destructible
void destruct(void *ptr) const
T & construct(Args &&...args)
void add_destruct_call(Func func)
void * allocate_owned(const CPPType &type)
LinearAllocator & allocator()
T * add(std::unique_ptr< T > resource)
ResourceScope(int64_t initial_size=32)
NonMovable(NonMovable &&other)=delete
void free(Subdiv *subdiv)
std::unique_ptr< T, DestructValueAtAddress< T > > destruct_ptr
BMesh const char void * data