/usr/include/deal.II/lac/vector_memory.templates.h is in libdeal.ii-dev 8.4.2-2+b1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | // ---------------------------------------------------------------------
//
// Copyright (C) 2007 - 2015 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE at
// the top level of the deal.II distribution.
//
// ---------------------------------------------------------------------
#ifndef dealii__vector_memory_templates_h
#define dealii__vector_memory_templates_h
#include <deal.II/lac/vector_memory.h>
DEAL_II_NAMESPACE_OPEN
template <typename VectorType>
typename GrowingVectorMemory<VectorType>::Pool GrowingVectorMemory<VectorType>::pool;
template <typename VectorType>
Threads::Mutex GrowingVectorMemory<VectorType>::mutex;
template <typename VectorType>
inline
GrowingVectorMemory<VectorType>::Pool::Pool()
:
data(0)
{}
template <typename VectorType>
inline
GrowingVectorMemory<VectorType>::Pool::~Pool()
{
// Nothing to do if memory was unused.
if (data == 0) return;
// First, delete all remaining
// vectors. Actually, there should
// be none, if there is no memory
// leak
for (typename std::vector<entry_type>::iterator i=data->begin();
i != data->end();
++i)
{
delete i->second;
}
delete data;
}
template <typename VectorType>
inline
void
GrowingVectorMemory<VectorType>::Pool::initialize(const size_type size)
{
if (data == 0)
{
data = new std::vector<entry_type>(size);
for (typename std::vector<entry_type>::iterator i= data->begin();
i != data->end();
++i)
{
i->first = false;
i->second = new VectorType;
}
}
}
template <typename VectorType>
inline
GrowingVectorMemory<VectorType>::GrowingVectorMemory (const size_type initial_size,
const bool log_statistics)
:
total_alloc(0),
current_alloc(0),
log_statistics(log_statistics)
{
Threads::Mutex::ScopedLock lock(mutex);
pool.initialize(initial_size);
}
template<typename VectorType>
inline
GrowingVectorMemory<VectorType>::~GrowingVectorMemory()
{
AssertNothrow(current_alloc == 0,
StandardExceptions::ExcMemoryLeak(current_alloc));
if (log_statistics)
{
deallog << "GrowingVectorMemory:Overall allocated vectors: "
<< total_alloc << std::endl;
deallog << "GrowingVectorMemory:Maximum allocated vectors: "
<< pool.data->size() << std::endl;
}
}
template<typename VectorType>
inline
VectorType *
GrowingVectorMemory<VectorType>::alloc ()
{
Threads::Mutex::ScopedLock lock(mutex);
++total_alloc;
++current_alloc;
// see if there is a free vector
// available in our list
for (typename std::vector<entry_type>::iterator i=pool.data->begin();
i != pool.data->end(); ++i)
{
if (i->first == false)
{
i->first = true;
return (i->second);
}
}
// no free vector found, so let's
// just allocate a new one
const entry_type t (true, new VectorType);
pool.data->push_back(t);
return t.second;
}
template<typename VectorType>
inline
void
GrowingVectorMemory<VectorType>::free(const VectorType *const v)
{
Threads::Mutex::ScopedLock lock(mutex);
for (typename std::vector<entry_type>::iterator i=pool.data->begin();
i != pool.data->end(); ++i)
{
if (v == (i->second))
{
i->first = false;
--current_alloc;
return;
}
}
Assert(false, typename VectorMemory<VectorType>::ExcNotAllocatedHere());
}
template<typename VectorType>
inline
void
GrowingVectorMemory<VectorType>::release_unused_memory ()
{
Threads::Mutex::ScopedLock lock(mutex);
std::vector<entry_type> new_data;
if (pool.data != 0)
{
const typename std::vector<entry_type>::const_iterator
end = pool.data->end();
for (typename std::vector<entry_type>::const_iterator
i = pool.data->begin(); i != end ; ++i)
if (i->first == false)
delete i->second;
else
new_data.push_back (*i);
*pool.data = new_data;
}
}
template<typename VectorType>
inline
std::size_t
GrowingVectorMemory<VectorType>::memory_consumption () const
{
Threads::Mutex::ScopedLock lock(mutex);
std::size_t result = sizeof (*this);
const typename std::vector<entry_type>::const_iterator
end = pool.data->end();
for (typename std::vector<entry_type>::const_iterator
i = pool.data->begin(); i != end ; ++i)
result += sizeof (*i) + i->second->memory_consumption();
return result;
}
DEAL_II_NAMESPACE_CLOSE
#endif
|