HL-HDF
hlhdf_alloc.h
Go to the documentation of this file.
1/* --------------------------------------------------------------------
2Copyright (C) 2009 Swedish Meteorological and Hydrological Institute, SMHI,
3
4This file is part of HLHDF.
5
6HLHDF is free software: you can redistribute it and/or modify
7it under the terms of the GNU Lesser General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11HLHDF is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU Lesser General Public License for more details.
15
16You should have received a copy of the GNU Lesser General Public License
17along with HLHDF. If not, see <http://www.gnu.org/licenses/>.
18------------------------------------------------------------------------*/
19
26#ifndef HLHDF_ALLOC_H
27#define HLHDF_ALLOC_H
28#include <stdlib.h>
29
37void* hlhdf_alloc_malloc(const char* filename, int lineno, size_t sz);
38
46void* hlhdf_alloc_calloc(const char* filename, int lineno, size_t npts, size_t sz);
47
55void* hlhdf_alloc_realloc(const char* filename, int lineno, void* ptr, size_t sz);
56
63char* hlhdf_alloc_strdup(const char* filename, int lineno, const char* str);
64
71void hlhdf_alloc_free(const char* filename, int lineno, void* ptr);
72
76void hlhdf_alloc_dump_heap(void);
77
82
83#ifdef HLHDF_MEMORY_DEBUG
87#define HLHDF_MALLOC(sz) hlhdf_alloc_malloc(__FILE__, __LINE__, sz)
88
92#define HLHDF_CALLOC(npts,sz) hlhdf_alloc_calloc(__FILE__, __LINE__, npts, sz)
93
97#define HLHDF_REALLOC(ptr, sz) hlhdf_alloc_realloc(__FILE__, __LINE__, ptr, sz)
98
102#define HLHDF_STRDUP(x) hlhdf_alloc_strdup(__FILE__, __LINE__, x)
103
107#define HLHDF_FREE(x) if (x != NULL) {hlhdf_alloc_free(__FILE__, __LINE__, x); x=NULL;}
108
109#else
113#define HLHDF_MALLOC(sz) malloc(sz)
114
118#define HLHDF_CALLOC(npts,sz) calloc(npts, sz)
119
123#define HLHDF_REALLOC(ptr, sz) realloc(ptr, sz)
124
128#define HLHDF_STRDUP(x) strdup(x)
129
133#define HLHDF_FREE(x) if (x != NULL) {free(x);x=NULL;}
134
135#endif
136
137#endif /* HLHDF_ALLOC_H */
void hlhdf_alloc_dump_heap(void)
Dumps all blocks that not has been released.
Definition hlhdf_alloc.c:301
void * hlhdf_alloc_malloc(const char *filename, int lineno, size_t sz)
Allocates memory and keeps track on if it is released, overwritten and similar.
Definition hlhdf_alloc.c:186
void * hlhdf_alloc_calloc(const char *filename, int lineno, size_t npts, size_t sz)
Same as calloc but debugged.
Definition hlhdf_alloc.c:200
void * hlhdf_alloc_realloc(const char *filename, int lineno, void *ptr, size_t sz)
Same as realloc but debugged.
Definition hlhdf_alloc.c:220
void hlhdf_alloc_print_statistics(void)
Prints the statistics for the heap.
Definition hlhdf_alloc.c:320
void hlhdf_alloc_free(const char *filename, int lineno, void *ptr)
Releases the memory.
Definition hlhdf_alloc.c:275
char * hlhdf_alloc_strdup(const char *filename, int lineno, const char *str)
Same as strdup but debugged.
Definition hlhdf_alloc.c:248