Reference documentation for deal.II version 9.3.3
\(\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\}}\)
vector_memory.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 1998 - 2020 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
25
26#include <deal.II/lac/vector.h>
27
28#include <iostream>
29#include <memory>
30#include <vector>
31
33
34
37
103template <typename VectorType = ::Vector<double>>
105{
106public:
112 virtual ~VectorMemory() override = default;
113
132 virtual VectorType *
133 alloc() = 0;
134
149 virtual void
150 free(const VectorType *const) = 0;
151
162 "You are trying to deallocate a vector from a memory pool, but this "
163 "vector has not actually been allocated by the same pool before.");
164
166
188 : public std::unique_ptr<VectorType, std::function<void(VectorType *)>>
189 {
190 public:
198 Pointer() = default;
199
204 Pointer(Pointer &&p) noexcept = default;
205
210 Pointer &
211 operator=(Pointer &&p) noexcept = default;
212
218
222 ~Pointer() = default;
223 };
224};
225
226
227
235template <typename VectorType = ::Vector<double>>
236class PrimitiveVectorMemory : public VectorMemory<VectorType>
237{
238public:
261 virtual VectorType *
262 alloc() override;
263
281 virtual void
282 free(const VectorType *const v) override;
283};
284
285
286
312template <typename VectorType = ::Vector<double>>
313class GrowingVectorMemory : public VectorMemory<VectorType>
314{
315public:
320
325 GrowingVectorMemory(const size_type initial_size = 0,
326 const bool log_statistics = false);
327
334 virtual ~GrowingVectorMemory() override;
335
354 virtual VectorType *
355 alloc() override;
356
374 virtual void
375 free(const VectorType *const) override;
376
380 static void
382
386 virtual std::size_t
388
389private:
396 using entry_type = std::pair<bool, std::unique_ptr<VectorType>>;
397
405 struct Pool
406 {
411
416
420 void
422
426 std::vector<entry_type> *data;
427 };
428
432 static Pool &
434
440
446
451
457};
458
459
460
461namespace internal
462{
463 namespace GrowingVectorMemoryImplementation
464 {
465 void
467 }
468} // namespace internal
469
472#ifndef DOXYGEN
473/* --------------------- inline functions ---------------------- */
474
475
476template <typename VectorType>
478 : std::unique_ptr<VectorType, std::function<void(VectorType *)>>(
479 mem.alloc(),
480 [&mem](VectorType *v) { mem.free(v); })
481{}
482
483
484
485template <typename VectorType>
486VectorType *
488{
489 return new VectorType();
490}
491
492
493
494template <typename VectorType>
495void
496PrimitiveVectorMemory<VectorType>::free(const VectorType *const v)
497{
498 delete v;
499}
500
501
502
503#endif // DOXYGEN
504
506
507#endif
virtual VectorType * alloc()=0
virtual ~VectorMemory() override=default
virtual void free(const VectorType *const)=0
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:402
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:403
void initialize(const size_type size)
virtual VectorType * alloc() override
virtual void free(const VectorType *const v) override
static void release_unused_memory()
static ::ExceptionBase & ExcNotAllocatedHere()
std::vector< entry_type > * data
Pointer & operator=(Pointer &&p) noexcept=default
static Pool & get_pool()
Pointer(Pointer &&p) noexcept=default
Pointer(VectorMemory< VectorType > &mem)
static Threads::Mutex mutex
virtual void free(const VectorType *const) override
virtual std::size_t memory_consumption() const
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:493
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 VectorType * alloc() override
STL namespace.
unsigned int global_dof_index
Definition: types.h:76