-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmemory_dmalloc.c
145 lines (115 loc) · 3.73 KB
/
memory_dmalloc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*BHEADER**********************************************************************
* Copyright (c) 2017, Lawrence Livermore National Security, LLC.
* Produced at the Lawrence Livermore National Laboratory.
* Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322.
* This file is part of AMG. See files README and COPYRIGHT for details.
*
* AMG is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License (as published by the Free
* Software Foundation) version 2.1 dated February 1999.
*
* This software is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the
* GNU General Public License for more details.
*
***********************************************************************EHEADER*/
/******************************************************************************
*
* Memory management utilities
*
* Routines to use "Debug Malloc Library", dmalloc
*
*****************************************************************************/
#ifdef HYPRE_MEMORY_DMALLOC
#include "hypre_memory.h"
#include <dmalloc.h>
char dmalloc_logpath_memory[256];
/*--------------------------------------------------------------------------
* hypre_InitMemoryDebugDML
*--------------------------------------------------------------------------*/
HYPRE_Int
hypre_InitMemoryDebugDML( HYPRE_Int id )
{
HYPRE_Int *iptr;
/* do this to get the Debug Malloc Library started/initialized */
iptr = hypre_TAlloc(HYPRE_Int, 1);
hypre_TFree(iptr);
dmalloc_logpath = dmalloc_logpath_memory;
hypre_sprintf(dmalloc_logpath, "dmalloc.log.%04d", id);
return 0;
}
/*--------------------------------------------------------------------------
* hypre_FinalizeMemoryDebugDML
*--------------------------------------------------------------------------*/
HYPRE_Int
hypre_FinalizeMemoryDebugDML( )
{
dmalloc_verify(NULL);
return 0;
}
/*--------------------------------------------------------------------------
* hypre_MAllocDML
*--------------------------------------------------------------------------*/
char *
hypre_MAllocDML( HYPRE_Int size,
char *file,
HYPRE_Int line )
{
char *ptr;
if (size > 0)
ptr = _malloc_leap(file, line, size);
else
ptr = NULL;
return ptr;
}
/*--------------------------------------------------------------------------
* hypre_CAllocDML
*--------------------------------------------------------------------------*/
char *
hypre_CAllocDML( HYPRE_Int count,
HYPRE_Int elt_size,
char *file,
HYPRE_Int line )
{
char *ptr;
HYPRE_Int size = count*elt_size;
if (size > 0)
{
ptr = _calloc_leap(file, line, count, elt_size);
}
else
{
ptr = NULL;
}
return ptr;
}
/*--------------------------------------------------------------------------
* hypre_ReAllocDML
*--------------------------------------------------------------------------*/
char *
hypre_ReAllocDML( char *ptr,
HYPRE_Int size,
char *file,
HYPRE_Int line )
{
ptr = _realloc_leap(file, line, ptr, size);
return ptr;
}
/*--------------------------------------------------------------------------
* hypre_FreeDML
*--------------------------------------------------------------------------*/
void
hypre_FreeDML( char *ptr,
char *file,
HYPRE_Int line )
{
if (ptr)
{
_free_leap(file, line, ptr);
}
}
#else
/* this is used only to eliminate compiler warnings */
char hypre_memory_dmalloc_empty;
#endif