"Fossies" - the Fresh Open Source Software Archive 
Member "FunctionCheck-3.2.0/src/fcmanager/fc_memory_manager.h" (26 May 2012, 3326 Bytes) of package /linux/privat/old/FunctionCheck-3.2.0.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /*
2 * FunctionCheck profiler
3 * (C) Copyright 2000-2012 Yannick Perret
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /** fc_memory_manager.h: **/
20
21 #ifndef __fc_memory_manager_h_
22 #define __fc_memory_manager_h_
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include "fc_xhash.h"
27
28 /** structure of memory list entries **/
29 /* a such entry is created for each 'malloc/memalign'.
30 for each realloc 'pointer' and 'realloc_place' are updated
31 in case of free the entry is removed
32
33 in case of free on a unknown entry (i.e. previously freed
34 pointer) the entry is removed from the access table (hash-table)
35 but not from the list (pointer/alloc place are used, and
36 size is set to MAX_UINT)
37 */
38 #define FC_MAX_CALLSTACK 8
39
40 typedef struct
41 {
42 void *pointer; /* the pointer on the memory block */
43 unsigned int size; /* orig. size of the block */
44 void *alloc_place; /* addr in prog. space of the allocation */
45 void *realloc_place;/* addr in prog. space of the last reallocation */
46 int next; /* next entry */
47 int self; /* our own index for optimization */
48 void *alloc_stack[FC_MAX_CALLSTACK]; /* call-stack for alloc place (max 8) */
49 char set;
50 } FC_MEl;
51
52 typedef struct
53 {
54 int nb_elements;
55 int max_elements;
56 int entry;
57 FC_MEl *list;
58 FC_Hash *hash;
59 } FC_Memory;
60
61 /* hum... this include MUST be here because some functions below
62 use FC_Context structure, BUT FC_Context uses FC_Memory...
63 so FC_Memory MUST be defined BEFORE including fc_context.h...
64 In fact my .h have to be reorganized... */
65 #include "fc_context.h"
66
67 /* indicate the call-stack requested for memory actions */
68 extern int fc_memory_stack_size;
69
70 /* set the call-stack size requested */
71 int fc_memory_set_stack_size(int size);
72
73 /* create a memory */
74 FC_Memory *fc_memory_create(int entry_size);
75
76 /* destroy a memory */
77 int fc_memory_delete(FC_Memory *mem);
78
79 /* add an element in a memory/list (with reallocation if needed) and
80 return the address of the element for the hash-table */
81 FC_MEl *fc_memory_list_add(FC_Memory *mem);
82
83 /* remove an element from the memory/list */
84 int fc_memory_list_remove(FC_Memory *mem, FC_MEl *el);
85
86 /* record a 'malloc' entry */
87 int fc_memory_add_malloc(void *ctx, void *ptr, unsigned int size, void *where);
88
89 /* record a 'memalign' entry */
90 int fc_memory_add_memalign(void *ctx, void *ptr, unsigned int align, unsigned int size, void *where);
91
92 /* record a 'free' action */
93 int fc_memory_add_free(void *ctx, void *ptr, void *where);
94
95 /* record a 'realloc' entry */
96 int fc_memory_add_realloc(void *ctx, void *ptr, void *inc, unsigned int size, void *where);
97
98 #endif /* __fc_memory_manager_h_ */