From 57d7ae0365b44752b8c38c3046d8f1b76c72362b Mon Sep 17 00:00:00 2001 From: Peter Schlaile Date: Sun, 5 Feb 2006 18:56:30 +0000 Subject: Adds generic memcache limitor (used by the new sequencer to cache only a certain amount of frames). --- intern/memutil/MEM_Allocator.h | 89 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 intern/memutil/MEM_Allocator.h (limited to 'intern/memutil/MEM_Allocator.h') diff --git a/intern/memutil/MEM_Allocator.h b/intern/memutil/MEM_Allocator.h new file mode 100644 index 00000000000..40716496d16 --- /dev/null +++ b/intern/memutil/MEM_Allocator.h @@ -0,0 +1,89 @@ +/** + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Contributor(s): Peter Schlaile 2005 + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#ifndef __MEM_Allocator_h_included__ +#define __MEM_Allocator_h_included__ 1 + +#include "guardedalloc/MEM_guardedalloc.h" + +template +struct MEM_Allocator +{ + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Tp* pointer; + typedef const _Tp* const_pointer; + typedef _Tp& reference; + typedef const _Tp& const_reference; + typedef _Tp value_type; + + template + struct rebind { + typedef MEM_Allocator<_Tp1> other; + }; + + MEM_Allocator() throw() {} + MEM_Allocator(const MEM_Allocator& __a) throw() {} + + template + MEM_Allocator(const MEM_Allocator<_Tp1> __a) throw() { } + + ~MEM_Allocator() throw() {} + + pointer address(reference __x) const { return &__x; } + + const_pointer address(const_reference __x) const { return &__x; } + + // NB: __n is permitted to be 0. The C++ standard says nothing + // about what the return value is when __n == 0. + _Tp* allocate(size_type __n, const void* = 0) { + _Tp* __ret = 0; + if (__n) + __ret = static_cast<_Tp*>( + MEM_mallocN(__n * sizeof(_Tp), + "STL MEM_Allocator")); + return __ret; + } + + // __p is not permitted to be a null pointer. + void deallocate(pointer __p, size_type){ + MEM_freeN(__p); + } + + size_type max_size() const throw() { + return size_t(-1) / sizeof(_Tp); + } + + void construct(pointer __p, const _Tp& __val) { + new(__p) _Tp(__val); + } + + void destroy(pointer __p) { + __p->~_Tp(); + } +}; + +#endif -- cgit v1.2.3