casacore
Loading...
Searching...
No Matches
Memory.h
Go to the documentation of this file.
1//# Memory.h: Memory related information and utilities.
2//# Copyright (C) 1997,2001
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_MEMORY_H
27#define CASA_MEMORY_H
28
29#include <casacore/casa/aips.h>
30//# The following is used to get size_t.
31#include <casacore/casa/stdlib.h>
32
33namespace casacore { //# NAMESPACE CASACORE - BEGIN
34
35// <summary>Memory related information and utilities.</summary>
36
37// use visibility=export>
38
39// <reviewed reviewer="rmarson" date="1997/11/12" tests="tMemory" demos="">
40// </reviewed>
41
42// <prerequisite>
43// <li> General knowledge of C/C++ memory allocation issues.
44// </prerequisite>
45//
46// <synopsis>
47// This class should generally not be used by general application programmers.
48// Instead you should use the memory information available in the
49// <linkto class=AppInfo>AppInfo</linkto> class.
50//
51// This class reports on the dynamic ("heap") memory used by this process, and
52// it can attempt to release some of that memory back to the operating
53// system. The class reports on <src>allocated</src> memory, which is memory
54// that the process has actually requested, typically via <src>new</src>, but
55// also via <src>malloc</src>. The number might be somewhat larger than actually
56// requested by the programmer to account for overhead and alignment
57// considerations. The class also reports <src>assigned</src> memory, which is
58// the total memory that the process has been given, not all of which has been
59// allocated by the programmer. Typically this results from memory which has
60// been <src>delete</src>d by the programmer, but has not been released to the
61// OS on the assumption that it might be needed again. (Getting and releasing
62// memory to the OS can be expensive).
63//
64// At present, the values for allocated and assigned memory are obtained via the
65// <src>mallinfo()</src> call, usually defined in <src>malloc.h</src>. This call
66// seems to be adequately portable for Unix. Another alternative would be to
67// replace global operators <src>new</src> and <src>delete</src> for systems
68// that do not have <src>mallinfo()</src>.
69//
70// The member function <src>releaseMemory()</src> on some system will attempt
71// to return assigned but unallocated memory to the OS. If the compilation
72// system cannot automatically determine how to do this (at present it only
73// recognizes Linux systems), you can you this function by setting the
74// preprocessor symbol <src>AIPS_RELEASEMEM</src> to a C++ statement which
75// will release memory to the OS. For example, if you are using GNU malloc
76// you could set it to <src>malloc_trim(0)</src>. Note that
77// <src>releaseMemory()</src> might be a no-op on many systems, and that
78// calling it might be expensive so it should not be called in tight-loops.
79//
80// Note that this class does not use any Casacore facilities and does not cause
81// any Casacore code to be linked in to your executable.
82// </synopsis>
83//
84// <example>
85// We could attempt to return memory to the OS when we are wasting a lot
86// of memory as follows.
87// <srcBlock>
88// if (Memory::assignedMemoryInBytes() - Memory::allocatedMemoryInBytes() >
89// 1024*1024) {
90// Memory::releaseMemory(); // Attempt to release if more than 1M "wasted"
91// }
92// </srcBlock>
93// </example>
94//
95// <motivation>
96// At run time we need to be able to make decisions about whether we should
97// keep things in memory or about whether we should do I/O (e.g. use an
98// Array or a PagedArray).
99// </motivation>
100//
101// <todo asof="1997/11/10">
102// <li> We might some day want to put actual allocation/deallocation
103// functions in here if the mallinfo() interface turns out to not
104// be portable.
105// </todo>
106
108{
109public:
110 // Attempt to release memory which has been assigned but not allocated.
111 // On many systems this will be a no-op, and even on systems in which it
112 // does something the amount of reclaimed memory cannot be specified.
113 // Since this function may be somewhat expensive to call it should not
114 // be called too often.
115 [[deprecated("This function calls malloc_trim(), which is is mostly an artefact and not effective on modern systems")]]
116 static void releaseMemory();
117
118 // setMemoryOptions and setMemoryOption are typically front ends for mallopt
119 // which lets the user control some memory allocation parameters. setMemoryOptions
120 // is intended to be called only once at the start of a program while setMemoryOption
121 // could be called where desired (but see mallopt man page for possible side effects).
122 // Note: these two functions were added to address in a general way a memory
123 // fragmentation problem encountered on by the MIPSpro C++ compiler on the SGI.
124 static void setMemoryOptions();
125 static int setMemoryOption(int, int);
126};
127
128
129} //# NAMESPACE CASACORE - END
130
131#endif
132
133
static int setMemoryOption(int, int)
static void releaseMemory()
Attempt to release memory which has been assigned but not allocated.
static void setMemoryOptions()
setMemoryOptions and setMemoryOption are typically front ends for mallopt which lets the user control...
this file contains all the compiler specific defines
Definition mainpage.dox:28