Antares Simulator
Power System Simulator
memory.h
1 /*
2 ** Copyright 2007-2025, RTE (https://www.rte-france.com)
3 ** See AUTHORS.txt
4 ** SPDX-License-Identifier: MPL-2.0
5 ** This file is part of Antares-Simulator,
6 ** Adequacy and Performance assessment for interconnected energy networks.
7 **
8 ** Antares_Simulator is free software: you can redistribute it and/or modify
9 ** it under the terms of the Mozilla Public Licence 2.0 as published by
10 ** the Mozilla Foundation, either version 2 of the License, or
11 ** (at your option) any later version.
12 **
13 ** Antares_Simulator is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** Mozilla Public Licence 2.0 for more details.
17 **
18 ** You should have received a copy of the Mozilla Public Licence 2.0
19 ** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20 */
21 #ifndef __ANTARES_LIBS_MEMORY_MEMORY_H__
22 #define __ANTARES_LIBS_MEMORY_MEMORY_H__
23 
24 #include <yuni/yuni.h>
25 #include <yuni/core/bit/array.h>
26 #include <yuni/core/string.h>
27 
28 namespace Antares
29 {
33 class Memory final: public Yuni::Policy::ObjectLevelLockable<Memory>
34 {
35 public:
36  template<class T>
37  struct Stored final
38  {
39  using Type = T*;
40  using ReturnType = T*;
41  using ConstReturnType = const T*;
42 
43  static const T* NullValue()
44  {
45  return nullptr;
46  }
47  };
48 
49  template<class U>
50  static U* RawPointer(U* array);
51 
52  template<class U>
53  static void Zero(uint count, U* array);
54 
55  template<class U>
56  static void Assign(uint count, U* array, const U& value);
57 
58  template<class T>
59  static void Allocate(T*& out, size_t size);
60 
61  template<class T>
62  static bool Null(const T* out);
63 
64  template<class T>
65  static bool StrictNull(const T* out);
66 
70  template<class T>
71  static void Release(T*& pointer);
72 
74 
75 
78  Memory() = default;
82  ~Memory() = default;
84 
85  bool initializeTemporaryFolder();
87 
89 
90  const Yuni::String& cacheFolder() const;
91  void cacheFolder(const AnyString& folder);
93 
99  uint64_t processID() const;
100 
102 
104 
105  void displayInfo() const;
108 
109 private:
111  Yuni::String pCacheFolder;
113  bool pAllowedToChangeCacheFolder;
114 
116  uint64_t pProcessID;
117 
119  bool pAlreadyInitialized = false;
120 
121  // Friend
122  template<class T>
123  friend class Array;
124 
125 }; // class Memory
126 
128 extern Memory memory;
129 
130 } // namespace Antares
131 
132 #include "memory.hxx"
133 
134 #endif // __ANTARES_LIBS_MEMORY_MEMORY_H__
Custom memory allocator for managed pointers.
Definition: memory.h:34
Memory()=default
Default Constructor.
const Yuni::String & cacheFolder() const
\nane Cache Folder
Definition: memory.cpp:137
~Memory()=default
Destructor.
static void Release(T *&pointer)
Release a raw pointer.
Definition: memory.hxx:32
void displayInfo() const
Display infos into the logs.
Definition: memory.cpp:122
uint64_t processID() const
Get the process ID of the application.
Definition: memory.hxx:26
Definition: memory.h:38