source: codes/icosagcm/branches/SATURN_DYNAMICO/XIOS/src/memtrack.hpp @ 309

Last change on this file since 309 was 248, checked in by ymipsl, 10 years ago

Adding XIOS directory

YM

File size: 2.7 KB
RevLine 
[248]1#ifdef XIOS_MEMTRACK
2/*
3Copyright (c) 2002, 2008 Curtis Bartley
4All rights reserved.
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions
7are met:
8
9- Redistributions of source code must retain the above copyright
10notice, this list of conditions and the following disclaimer.
11
12- Redistributions in binary form must reproduce the above copyright
13notice, this list of conditions and the following disclaimer in the
14documentation and/or other materials provided with the
15distribution.
16
17- Neither the name of Curtis Bartley nor the names of any other
18contributors may be used to endorse or promote products derived
19from this software without specific prior written permission.
20
21THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32OF THE POSSIBILITY OF SUCH DAMAGE.
33*/
34
35#ifndef MemTrack_H_
36#define MemTrack_H_
37
38#include <typeinfo>
39#include <cstring>
40
41namespace MemTrack
42{
43    /* ---------------------------------------- class MemStamp */
44
45    class MemStamp
46    {
47        public:        // member variables
48            char const * const filename;
49            int const lineNum;
50        public:        // construction/destruction
51            MemStamp(char const *filename, int lineNum)
52                : filename(filename), lineNum(lineNum) { }
53            ~MemStamp() { }
54    };
55
56    /* ---------------------------------------- memory allocation and stamping prototypes */
57
58    void *TrackMalloc(size_t size);
59    void TrackFree(void *p);
60    void TrackStamp(void *p, const MemStamp &stamp, char const *typeName);
61    void TrackDumpBlocks();
62    void TrackListMemoryUsage();
63
64    /* ---------------------------------------- operator * (MemStamp, ptr) */
65
66    template <class T> inline T *operator*(const MemStamp &stamp, T *p)
67    {
68        TrackStamp(p, stamp, typeid(T).name());
69        return p;
70    }
71
72}    // namespace MemTrack
73
74/* ---------------------------------------- new macro */
75
76#define MEMTRACK_NEW MemTrack::MemStamp(__FILE__, __LINE__) * new
77#define new MEMTRACK_NEW
78
79#endif    // MemTrack_H_
80
81#endif
Note: See TracBrowser for help on using the repository browser.