diff options
Diffstat (limited to 'intern/memutil')
-rw-r--r-- | intern/memutil/CMakeLists.txt | 1 | ||||
-rw-r--r-- | intern/memutil/MEM_Allocator.h | 1 | ||||
-rw-r--r-- | intern/memutil/MEM_CacheLimiter.h | 39 | ||||
-rw-r--r-- | intern/memutil/MEM_CacheLimiterC-Api.h | 7 | ||||
-rw-r--r-- | intern/memutil/MEM_NonCopyable.h | 1 | ||||
-rw-r--r-- | intern/memutil/MEM_RefCountPtr.h | 1 | ||||
-rw-r--r-- | intern/memutil/MEM_RefCounted.h | 1 | ||||
-rw-r--r-- | intern/memutil/MEM_RefCountedC-Api.h | 1 | ||||
-rw-r--r-- | intern/memutil/MEM_SmartPtr.h | 1 | ||||
-rw-r--r-- | intern/memutil/intern/MEM_CacheLimiterC-Api.cpp | 10 | ||||
-rw-r--r-- | intern/memutil/intern/MEM_RefCountedC-Api.cpp | 1 |
11 files changed, 46 insertions, 18 deletions
diff --git a/intern/memutil/CMakeLists.txt b/intern/memutil/CMakeLists.txt index 54e43cb7236..3f9f8d6fe25 100644 --- a/intern/memutil/CMakeLists.txt +++ b/intern/memutil/CMakeLists.txt @@ -1,4 +1,3 @@ -# $Id$ # ***** BEGIN GPL LICENSE BLOCK ***** # # This program is free software; you can redistribute it and/or diff --git a/intern/memutil/MEM_Allocator.h b/intern/memutil/MEM_Allocator.h index 14d62a2434d..99d0b5177f3 100644 --- a/intern/memutil/MEM_Allocator.h +++ b/intern/memutil/MEM_Allocator.h @@ -1,5 +1,4 @@ /* - * * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or diff --git a/intern/memutil/MEM_CacheLimiter.h b/intern/memutil/MEM_CacheLimiter.h index 0b657104a05..5194c97fd78 100644 --- a/intern/memutil/MEM_CacheLimiter.h +++ b/intern/memutil/MEM_CacheLimiter.h @@ -1,5 +1,4 @@ /* - * * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or @@ -126,6 +125,10 @@ class MEM_CacheLimiter { public: typedef typename std::list<MEM_CacheLimiterHandle<T> *, MEM_Allocator<MEM_CacheLimiterHandle<T> *> >::iterator iterator; + typedef intptr_t (*MEM_CacheLimiter_DataSize_Func) (void *data); + MEM_CacheLimiter(MEM_CacheLimiter_DataSize_Func getDataSize_) + : getDataSize(getDataSize_) { + } ~MEM_CacheLimiter() { for (iterator it = queue.begin(); it != queue.end(); it++) { delete *it; @@ -144,17 +147,36 @@ public: } void enforce_limits() { intptr_t max = MEM_CacheLimiter_get_maximum(); - intptr_t mem_in_use= MEM_get_memory_in_use(); - intptr_t mmap_in_use= MEM_get_mapped_memory_in_use(); + intptr_t mem_in_use, cur_size; if (max == 0) { return; } + + if(getDataSize) { + mem_in_use = total_size(); + } else { + mem_in_use = MEM_get_memory_in_use(); + } + for (iterator it = queue.begin(); - it != queue.end() && mem_in_use + mmap_in_use > max;) { + it != queue.end() && mem_in_use > max;) { iterator jt = it; ++it; + + if(getDataSize) { + cur_size= getDataSize((*jt)->get()->get_data()); + } else { + cur_size= mem_in_use; + } + (*jt)->destroy_if_possible(); + + if(getDataSize) { + mem_in_use-= cur_size; + } else { + mem_in_use-= cur_size - MEM_get_memory_in_use(); + } } } void touch(MEM_CacheLimiterHandle<T> * handle) { @@ -165,8 +187,17 @@ public: handle->me = it; } private: + intptr_t total_size() { + intptr_t size = 0; + for (iterator it = queue.begin(); it != queue.end(); it++) { + size+= getDataSize((*it)->get()->get_data()); + } + return size; + } + std::list<MEM_CacheLimiterHandle<T>*, MEM_Allocator<MEM_CacheLimiterHandle<T> *> > queue; + MEM_CacheLimiter_DataSize_Func getDataSize; }; #endif // MEM_CACHELIMITER_H diff --git a/intern/memutil/MEM_CacheLimiterC-Api.h b/intern/memutil/MEM_CacheLimiterC-Api.h index 4f267f7ddf0..768842caee6 100644 --- a/intern/memutil/MEM_CacheLimiterC-Api.h +++ b/intern/memutil/MEM_CacheLimiterC-Api.h @@ -1,5 +1,4 @@ /* - * * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or @@ -42,6 +41,9 @@ typedef struct MEM_CacheLimiterHandle_s MEM_CacheLimiterHandleC; /* function used to remove data from memory */ typedef void(*MEM_CacheLimiter_Destruct_Func)(void*); +/* function used to measure stored data element size */ +typedef intptr_t(*MEM_CacheLimiter_DataSize_Func) (void*); + #ifndef MEM_CACHELIMITER_H extern void MEM_CacheLimiter_set_maximum(int m); extern int MEM_CacheLimiter_get_maximum(void); @@ -55,7 +57,8 @@ extern int MEM_CacheLimiter_get_maximum(void); */ extern MEM_CacheLimiterC * new_MEM_CacheLimiter( - MEM_CacheLimiter_Destruct_Func data_destructor); + MEM_CacheLimiter_Destruct_Func data_destructor, + MEM_CacheLimiter_DataSize_Func data_size); /** * Delete MEM_CacheLimiter diff --git a/intern/memutil/MEM_NonCopyable.h b/intern/memutil/MEM_NonCopyable.h index 9b677f0e576..7ddd35d6fc4 100644 --- a/intern/memutil/MEM_NonCopyable.h +++ b/intern/memutil/MEM_NonCopyable.h @@ -1,5 +1,4 @@ /* - * $Id$ * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or diff --git a/intern/memutil/MEM_RefCountPtr.h b/intern/memutil/MEM_RefCountPtr.h index 2a1c92ad61c..43dbc807ae0 100644 --- a/intern/memutil/MEM_RefCountPtr.h +++ b/intern/memutil/MEM_RefCountPtr.h @@ -1,5 +1,4 @@ /* - * $Id$ * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or diff --git a/intern/memutil/MEM_RefCounted.h b/intern/memutil/MEM_RefCounted.h index 4f2edd0be09..0c3a54122f1 100644 --- a/intern/memutil/MEM_RefCounted.h +++ b/intern/memutil/MEM_RefCounted.h @@ -1,5 +1,4 @@ /* - * $Id$ * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or diff --git a/intern/memutil/MEM_RefCountedC-Api.h b/intern/memutil/MEM_RefCountedC-Api.h index 2f4297582af..4b2679cccc2 100644 --- a/intern/memutil/MEM_RefCountedC-Api.h +++ b/intern/memutil/MEM_RefCountedC-Api.h @@ -1,5 +1,4 @@ /* - * $Id$ * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or diff --git a/intern/memutil/MEM_SmartPtr.h b/intern/memutil/MEM_SmartPtr.h index ee3c4f22536..a2ab273d092 100644 --- a/intern/memutil/MEM_SmartPtr.h +++ b/intern/memutil/MEM_SmartPtr.h @@ -1,5 +1,4 @@ /* - * $Id$ * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or diff --git a/intern/memutil/intern/MEM_CacheLimiterC-Api.cpp b/intern/memutil/intern/MEM_CacheLimiterC-Api.cpp index 1bc011a5be0..cc8d2497f37 100644 --- a/intern/memutil/intern/MEM_CacheLimiterC-Api.cpp +++ b/intern/memutil/intern/MEM_CacheLimiterC-Api.cpp @@ -54,8 +54,8 @@ typedef std::list<MEM_CacheLimiterHandleCClass*, class MEM_CacheLimiterCClass { public: - MEM_CacheLimiterCClass(MEM_CacheLimiter_Destruct_Func data_destructor_) - : data_destructor(data_destructor_) { + MEM_CacheLimiterCClass(MEM_CacheLimiter_Destruct_Func data_destructor_, MEM_CacheLimiter_DataSize_Func data_size) + : data_destructor(data_destructor_), cache(data_size) { } ~MEM_CacheLimiterCClass(); @@ -142,10 +142,12 @@ static inline handle_t* cast(MEM_CacheLimiterHandleC * l) } MEM_CacheLimiterC * new_MEM_CacheLimiter( - MEM_CacheLimiter_Destruct_Func data_destructor) + MEM_CacheLimiter_Destruct_Func data_destructor, + MEM_CacheLimiter_DataSize_Func data_size) { return (MEM_CacheLimiterC*) new MEM_CacheLimiterCClass( - data_destructor); + data_destructor, + data_size); } void delete_MEM_CacheLimiter(MEM_CacheLimiterC * This) diff --git a/intern/memutil/intern/MEM_RefCountedC-Api.cpp b/intern/memutil/intern/MEM_RefCountedC-Api.cpp index d920592c94d..734596465a8 100644 --- a/intern/memutil/intern/MEM_RefCountedC-Api.cpp +++ b/intern/memutil/intern/MEM_RefCountedC-Api.cpp @@ -1,5 +1,4 @@ /* - * $Id$ * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or |