gwenhywfar  4.17.0
memory.h
Go to the documentation of this file.
1 /***************************************************************************
2  $RCSfile$
3  -------------------
4  cvs : $Id$
5  begin : Sat Jun 28 2003
6  copyright : (C) 2003 by Martin Preuss
7  email : martin@libchipcard.de
8 
9  ***************************************************************************
10  * *
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU Lesser General Public *
13  * License as published by the Free Software Foundation; either *
14  * version 2.1 of the License, or (at your option) any later version. *
15  * *
16  * This library is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
19  * Lesser General Public License for more details. *
20  * *
21  * You should have received a copy of the GNU Lesser General Public *
22  * License along with this library; if not, write to the Free Software *
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
24  * MA 02111-1307 USA *
25  * *
26  ***************************************************************************/
27 
28 
29 #ifndef GWENHYWFAR_MEMORY_H
30 #define GWENHYWFAR_MEMORY_H
31 
33 #include <gwenhywfar/types.h>
34 #include <gwenhywfar/error.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <assert.h>
39 
40 
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 
47 /* this is taken from the system header file assert.h and
48  * and modified by me (Martin Preuss).
49  */
50 # if defined __cplusplus ? __GNUC_PREREQ (2, 6) : __GNUC_PREREQ (2, 4)
51 # define GWEN_LOCATION_FUNCTION __PRETTY_FUNCTION__
52 # else
53 # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
54 # define GWEN_LOCATION_FUNCTION __func__
55 # else
56 # define GWEN_LOCATION_FUNCTION ((__const char *) "unknown function")
57 # endif
58 # endif
59 
60 
62 void *GWEN_Memory_malloc(size_t dsize);
64 void GWEN_Memory_dealloc(void *p);
65 
67 void *GWEN_Memory_realloc(void *oldp, size_t nsize);
68 
70 char *GWEN_Memory_strdup(const char *s);
71 
73 void GWEN_Memory_Collect(void);
74 
76 void GWEN_Memory_Dump(void);
77 
78 
79 #define GWEN_MEM_NEW(typ, memptr) \
80  memptr=(typ*)GWEN_Memory_malloc(sizeof(typ));
81 
82 #define GWEN_MEM_FREE(varname) \
83  GWEN_Memory_dealloc((void*)varname);
84 
85 
86 #define GWEN_NEW_OBJECT(typ, varname)\
87  {\
88  varname=(typ*)GWEN_Memory_malloc(sizeof(typ)); \
89  memset(varname, 0, sizeof(typ));\
90  }
91 
92 #define GWEN_FREE_OBJECT(varname) \
93  GWEN_Memory_dealloc((void*)varname);
94 
95 
96 #ifdef __cplusplus
97 }
98 #endif
99 
100 
101 #endif /* GWENHYWFAR_MEMORY_H */
102 
GWENHYWFAR_API void GWEN_Memory_dealloc(void *p)
GWENHYWFAR_API void GWEN_Memory_Dump(void)
GWENHYWFAR_API void * GWEN_Memory_realloc(void *oldp, size_t nsize)
GWENHYWFAR_API char * GWEN_Memory_strdup(const char *s)
GWENHYWFAR_API void GWEN_Memory_Collect(void)
#define GWENHYWFAR_API
Definition: gwenhywfarapi.h:67
GWENHYWFAR_API void * GWEN_Memory_malloc(size_t dsize)