Memory.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2016 Imperial College London
5  * Copyright 2013-2016 Andreas Schuh
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef MIRTK_Memory_H
21 #define MIRTK_Memory_H
22 
23 
24 // =============================================================================
25 // C/C++ library functions
26 // =============================================================================
27 
28 #include <cstring>
29 #include <utility>
30 #include <memory>
31 
32 namespace mirtk {
33 
34 
35 template <class T>
36 using UniquePtr = std::unique_ptr<T>;
37 
38 template <class T>
39 using SharedPtr = std::shared_ptr<T>;
40 
41 template <class T>
42 using WeakPtr = std::weak_ptr<T>;
43 
44 template <class T>
45 SharedPtr<T> NewShared()
46 {
47  return std::make_shared<T>();
48 }
49 
50 template <class T, class... Args>
51 SharedPtr<T> NewShared(Args&&... args)
52 {
53  return std::make_shared<T>(args...);
54 }
55 
56 using std::memset;
57 using std::memcpy;
58 using std::memmove;
59 using std::memcmp;
60 using std::swap;
61 
62 /// Byte order of each word in memory
64 {
65  UnknownByteOrder,
66  LittleEndian,
67  BigEndian
68 };
69 
70 /// Get byte order of this system
72 
73 /// Swap bytes of a single word
74 void swap16(char *, char *, long);
75 
76 /// Swap bytes of two word
77 void swap32(char *, char *, long);
78 
79 /// Swap bytes of four word
80 void swap64(char *, char *, long);
81 
82 /// Returns the peak (maximum so far) resident set size (physical
83 /// memory use) measured in bytes, or zero if the value cannot be
84 /// determined on this OS.
85 size_t GetPeakRSS();
86 
87 /// Returns the current resident set size (physical memory use) measured
88 /// in bytes, or zero if the value cannot be determined on this OS.
89 size_t GetCurrentRSS();
90 
91 
92 } // namespace mirtk
93 
94 // =============================================================================
95 // Allocate/Deallocate N-D arrays, Delete
96 // =============================================================================
97 
98 #include "mirtk/Allocate.h"
99 #include "mirtk/Deallocate.h"
100 
101 
102 #endif // MIRTK_Memory_H
Definition: IOConfig.h:41
void swap32(char *, char *, long)
Swap bytes of two word.
ByteOrder GetByteOrder()
Get byte order of this system.
ByteOrder
Byte order of each word in memory.
Definition: Memory.h:63
size_t GetCurrentRSS()
void swap64(char *, char *, long)
Swap bytes of four word.
size_t GetPeakRSS()
void swap16(char *, char *, long)
Swap bytes of a single word.