Nilorea Library

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Macros Groups
n_debug_mem.h
Go to the documentation of this file.
1
7 #ifndef N_DEBUG_MEM_HEADER_GUARD
8 #define N_DEBUG_MEM_HEADER_GUARD
9
10 #ifdef __cplusplus
11 extern "C"
12 {
13 #endif
14
20 #include <stdlib.h>
21 #include <pthread.h>
22
23 #ifdef DEBUG_MEM
24 #undef DEBUG_MEM
25 #include "n_hash.h"
26 #define DEBUG_MEM
27 #else
28 #include "n_hash.h"
29 #endif
30
32 #define DEBUG_MEM_DUMP_MAX_LEN 256
33
34 #if defined(_MSC_VER)
35
36 #define FORCE_INLINE __forceinline
37 #else
38 #ifdef SOLARIS
39
40 #define FORCE_INLINE __attribute__((always_inline))
41 #else
42
43 #define FORCE_INLINE inline __attribute__((always_inline))
44 #endif
45 #endif
46
48 typedef struct DEBUG_MEM_ITEM
49 {
51 void *ptr ;
53 size_t size ;
55 char *file ;
57 char *func ;
59 int line ;
60
61 }DEBUG_MEM_ITEM ;
62
64 typedef struct DEBUG_MEM_TABLE
65 {
67 int nb_malloc ;
69 int nb_free ;
71 HASH_TABLE *table ;
73 pthread_mutex_t lock ;
74
75 }DEBUG_MEM_TABLE ;
76
78 extern DEBUG_MEM_TABLE *debug_mem_table ;
79
80 #ifdef DEBUG_MEM
81 /* initialize debug tables */
82 int init_debug_mem();
83 /* new debug item */
84 DEBUG_MEM_ITEM *new_db_mem_item( void *ptr , size_t size , int line , char *file , char *func );
85 /* delete debug item */
86 void delete_db_mem_item( void *ptr );
87 /* debug malloc full */
88 FORCE_INLINE void *db_mem_alloc( size_t size , int line , char *file , const char *func );
89 /* debug malloc */
90 FORCE_INLINE void *db_malloc( size_t size );
91 /* debug free */
92 FORCE_INLINE void db_mem_free( void *ptr );
93 /* debug dump ! */
94 int db_mem_dump_leaked( char *file );
95 #endif
96
99 #ifdef __cplusplus
100 }
101 #endif
102
103 #endif