00001 /* 00002 * Copyright (c) 2011 Remko Tronçon 00003 * Licensed under the GNU General Public License v3. 00004 * See Documentation/Licenses/GPLv3.txt for more information. 00005 */ 00006 00007 #pragma once 00008 00009 #include <vector> 00010 #include <algorithm> 00011 00012 namespace Swift { 00013 template<typename T> 00014 class SafeAllocator : public std::allocator<T> { 00015 public: 00016 template <class U> struct rebind { 00017 typedef SafeAllocator<U> other; 00018 }; 00019 00020 SafeAllocator() throw() {} 00021 SafeAllocator(const SafeAllocator&) throw() : std::allocator<T>() {} 00022 template <class U> SafeAllocator(const SafeAllocator<U>&) throw() {} 00023 ~SafeAllocator() throw() {} 00024 00025 void deallocate (T* p, size_t num) { 00026 std::fill(reinterpret_cast<char*>(p), reinterpret_cast<char*>(p + num), 0); 00027 std::allocator<T>::deallocate(p, num); 00028 } 00029 }; 00030 };