9#ifndef __MEM_CACHELIMITER_H__
10#define __MEM_CACHELIMITER_H__
51#ifndef __MEM_CACHELIMITERC_API_H__
63 : data(data_), refcount(0), parent(parent_)
94 return !data || !refcount;
110 parent->unmanage(
this);
140 for (i = 0; i < queue.size(); i++) {
148 queue.back()->pos = queue.size() - 1;
154 int pos = handle->pos;
155 queue[
pos] = queue.back();
164 if (data_size_func) {
166 for (i = 0; i < queue.size(); i++) {
167 size += data_size_func(queue[i]->get()->get_data());
203 if (data_size_func) {
204 cur_size = data_size_func(elem->
get()->get_data());
211 if (data_size_func) {
227 if (item_priority_func ==
NULL) {
228 queue[handle->pos] = queue.back();
229 queue[handle->pos]->pos = handle->pos;
231 queue.push_back(handle);
232 handle->pos = queue.size() - 1;
238 this->item_priority_func = item_priority_func;
243 this->item_destroyable_func = item_destroyable_func;
248 typedef std::vector<MEM_CacheElementPtr, MEM_Allocator<MEM_CacheElementPtr>> MEM_CacheQueue;
249 typedef typename MEM_CacheQueue::iterator iterator;
252 bool can_destroy_element(MEM_CacheElementPtr &elem)
254 if (!elem->can_destroy()) {
258 if (item_destroyable_func) {
259 if (!item_destroyable_func(elem->get()->get_data())) {
266 MEM_CacheElementPtr get_least_priority_destroyable_element(
void)
272 MEM_CacheElementPtr best_match_elem =
NULL;
274 if (!item_priority_func) {
275 for (iterator it = queue.begin(); it != queue.end(); it++) {
276 MEM_CacheElementPtr elem = *it;
277 if (!can_destroy_element(elem)) {
280 best_match_elem = elem;
285 int best_match_priority = 0;
288 for (i = 0; i < queue.size(); i++) {
289 MEM_CacheElementPtr elem = queue[i];
291 if (!can_destroy_element(elem)) {
298 int priority = -((
int)(queue.size()) - i - 1);
299 priority = item_priority_func(elem->get()->get_data(), priority);
301 if (priority < best_match_priority || best_match_elem ==
NULL) {
302 best_match_priority = priority;
303 best_match_elem = elem;
308 return best_match_elem;
311 MEM_CacheQueue queue;
void MEM_CacheLimiter_set_maximum(size_t m)
void MEM_CacheLimiter_set_disabled(bool disabled)
size_t MEM_CacheLimiter_get_maximum()
bool MEM_CacheLimiter_is_disabled(void)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
bool destroy_if_possible()
MEM_CacheLimiterHandle(T *data_, MEM_CacheLimiter< T > *parent_)
void unmanage(MEM_CacheLimiterHandle< T > *handle)
int(* MEM_CacheLimiter_ItemPriority_Func)(void *item, int default_priority)
bool(* MEM_CacheLimiter_ItemDestroyable_Func)(void *item)
size_t(* MEM_CacheLimiter_DataSize_Func)(void *data)
size_t get_memory_in_use()
MEM_CacheLimiter(MEM_CacheLimiter_DataSize_Func data_size_func)
void set_item_destroyable_func(MEM_CacheLimiter_ItemDestroyable_Func item_destroyable_func)
void touch(MEM_CacheLimiterHandle< T > *handle)
void set_item_priority_func(MEM_CacheLimiter_ItemPriority_Func item_priority_func)
MEM_CacheLimiterHandle< T > * insert(T *elem)
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
size_t(* MEM_get_memory_in_use)(void)