Reference documentation for deal.II version 9.5.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
vector_memory.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 1998 - 2022 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16#ifndef dealii_vector_memory_h
17#define dealii_vector_memory_h
18
19
20#include <deal.II/base/config.h>
21
23#include <deal.II/base/mutex.h>
25
26#include <deal.II/lac/vector.h>
27
28#include <iostream>
29#include <memory>
30#include <vector>
31
33
34
105template <typename VectorType = ::Vector<double>>
107{
108public:
114 virtual ~VectorMemory() override = default;
115
134 virtual VectorType *
135 alloc() = 0;
136
151 virtual void
152 free(const VectorType *const) = 0;
153
164 "You are trying to deallocate a vector from a memory pool, but this "
165 "vector has not actually been allocated by the same pool before.");
166
190 : public std::unique_ptr<VectorType, std::function<void(VectorType *)>>
191 {
192 public:
200 Pointer() = default;
201
206 Pointer(Pointer &&p) noexcept = default;
207
212 Pointer &
213 operator=(Pointer &&p) noexcept = default;
214
220
224 ~Pointer() = default;
225 };
226};
227
228
229
237template <typename VectorType = ::Vector<double>>
238class PrimitiveVectorMemory : public VectorMemory<VectorType>
239{
240public:
263 virtual VectorType *
264 alloc() override;
265
283 virtual void
284 free(const VectorType *const v) override;
285};
286
287
288
314template <typename VectorType = ::Vector<double>>
315class GrowingVectorMemory : public VectorMemory<VectorType>
316{
317public:
322
327 GrowingVectorMemory(const size_type initial_size = 0,
328 const bool log_statistics = false);
329
336 virtual ~GrowingVectorMemory() override;
337
356 virtual VectorType *
357 alloc() override;
358
376 virtual void
377 free(const VectorType *const) override;
378
382 static void
384
388 virtual std::size_t
390
391private:
398 using entry_type = std::pair<bool, std::unique_ptr<VectorType>>;
399
407 struct Pool
408 {
413
418
422 void
424
428 std::vector<entry_type> *data;
429 };
430
434 static Pool &
436
442
448
453
459};
460
461
462
463namespace internal
464{
465 namespace GrowingVectorMemoryImplementation
466 {
467 void
469 }
470} // namespace internal
471
474#ifndef DOXYGEN
475/* --------------------- inline functions ---------------------- */
476
477
478template <typename VectorType>
480 : std::unique_ptr<VectorType, std::function<void(VectorType *)>>(
481 mem.alloc(),
482 [&mem](VectorType *v) { mem.free(v); })
483{}
484
485
486
487template <typename VectorType>
488VectorType *
490{
491 return new VectorType();
492}
493
494
495
496template <typename VectorType>
497void
498PrimitiveVectorMemory<VectorType>::free(const VectorType *const v)
499{
500 delete v;
501}
502
503
504
505#endif // DOXYGEN
506
508
509#endif
virtual VectorType * alloc() override
static void release_unused_memory()
static Pool & get_pool()
static Threads::Mutex mutex
virtual void free(const VectorType *const) override
virtual std::size_t memory_consumption() const
virtual ~GrowingVectorMemory() override
GrowingVectorMemory(const size_type initial_size=0, const bool log_statistics=false)
std::pair< bool, std::unique_ptr< VectorType > > entry_type
virtual void free(const VectorType *const v) override
virtual VectorType * alloc() override
Pointer & operator=(Pointer &&p) noexcept=default
Pointer(Pointer &&p) noexcept=default
Pointer(VectorMemory< VectorType > &mem)
virtual VectorType * alloc()=0
virtual ~VectorMemory() override=default
virtual void free(const VectorType *const)=0
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
static ::ExceptionBase & ExcNotAllocatedHere()
#define DeclExceptionMsg(Exception, defaulttext)
Definition exceptions.h:488
STL namespace.
unsigned int global_dof_index
Definition types.h:82
void initialize(const size_type size)
std::vector< entry_type > * data