3 //==========================================================================
7 * @author Priyanka Gontla <pgontla@ece.uci.edu>
8 * @author Based on code that existed in other ACE files.
10 //==========================================================================
12 #ifndef ACE_PI_MALLOC_H
13 #define ACE_PI_MALLOC_H
15 #include /**/ "ace/pre.h"
17 #include /**/ "ace/ACE_export.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
25 #include "ace/Malloc.h"
26 #include "ace/Based_Pointer_T.h"
28 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
30 // prepare for position independent malloc
32 * @class ACE_PI_Control_Block
34 * @brief This information is stored in memory allocated by the Memory_Pool.
36 * This class implements the control block structure that can be
37 * used in a "position independent" fashion, i.e., you don't need to
38 * "map" the underlying memory pool to the same address in
39 * processes sharing the memory. The trade off of this flexibility
40 * is more expensive malloc/free operations.
42 class ACE_Export ACE_PI_Control_Block
45 class ACE_Malloc_Header
;
48 typedef ACE_Based_Pointer
<ACE_Malloc_Header
> MALLOC_HEADER_PTR
;
49 typedef ACE_Based_Pointer
<ACE_Name_Node
> NAME_NODE_PTR
;
50 typedef ACE_Based_Pointer_Basic
<char> CHAR_PTR
;
53 * @class ACE_Malloc_Header
55 * @brief This is the control block header. It's used by ACE_Malloc
56 * to keep track of each chunk of data when it's in the free
59 class ACE_Export ACE_Malloc_Header
62 ACE_Malloc_Header (void);
64 /// Points to next block if on free list.
65 MALLOC_HEADER_PTR next_block_
;
67 /// Initialize a malloc header pointer.
68 static void init_ptr (MALLOC_HEADER_PTR
*ptr
,
69 ACE_Malloc_Header
*init
,
72 /// Size of this header control block.
75 # if !defined (ACE_PI_MALLOC_PADDING_SIZE)
76 # define ACE_PI_MALLOC_PADDING_SIZE ACE_MALLOC_ROUNDUP (ACE_MALLOC_HEADER_SIZE + sizeof (MALLOC_HEADER_PTR) + sizeof (size_t), ACE_MALLOC_ALIGN) - (sizeof (MALLOC_HEADER_PTR) + sizeof (size_t))
77 # endif /* !ACE_PI_MALLOC_PADDING_SIZE */
78 char padding_
[(ACE_PI_MALLOC_PADDING_SIZE
) ? ACE_PI_MALLOC_PADDING_SIZE
: ACE_MALLOC_ALIGN
];
80 /// Dump the state of the object.
81 void dump (void) const;
84 // Disallow copy construction and assignment.
85 ACE_Malloc_Header (ACE_Malloc_Header
const &);
86 void operator= (ACE_Malloc_Header
const &);
90 * @class ACE_Name_Node
92 * @brief This class supports "named memory regions" within ACE_Malloc.
94 * Internally, the named memory regions are stored as a
95 * doubly-linked list within the Memory_Pool. This makes
96 * it easy to iterate over the items in the list in both FIFO
99 class ACE_Export ACE_Name_Node
103 ACE_Name_Node (const char *name
,
106 ACE_Name_Node
*head
);
108 /// Copy constructor.
109 ACE_Name_Node (const ACE_Name_Node
&);
112 ACE_Name_Node (void);
115 ~ACE_Name_Node (void);
117 /// Initialize a name node pointer.
118 static void init_ptr (NAME_NODE_PTR
*ptr
,
122 /// Return a pointer to the name of this node.
123 const char *name (void) const;
126 void name (const char *);
128 /// Name of the Node.
131 /// Pointer to the contents.
134 /// Pointer to the next node in the doubly-linked list.
137 /// Pointer to the previous node in the doubly-linked list.
140 /// Dump the state of the object.
141 void dump (void) const;
144 // Disallow assignment.
145 void operator= (const ACE_Name_Node
&);
148 /// Print out a bunch of size info for debugging.
149 static void print_alignment_info (void);
151 /// Reference counter.
154 /// Head of the linked list of Name Nodes.
155 NAME_NODE_PTR name_head_
;
157 /// Current head of the freelist.
158 MALLOC_HEADER_PTR freep_
;
160 /// Name of lock thats ensures mutual exclusion.
161 char lock_name_
[MAXNAMELEN
];
163 #if defined (ACE_HAS_MALLOC_STATS)
164 /// Keep statistics about ACE_Malloc state and performance.
165 ACE_Malloc_Stats malloc_stats_
;
166 #define ACE_PI_CONTROL_BLOCK_SIZE ((int)(sizeof (NAME_NODE_PTR) \
167 + sizeof (MALLOC_HEADER_PTR) \
170 + sizeof (ACE_Malloc_Stats)))
172 #define ACE_PI_CONTROL_BLOCK_SIZE ((int)(sizeof (NAME_NODE_PTR) \
173 + sizeof (MALLOC_HEADER_PTR) \
176 #endif /* ACE_HAS_MALLOC_STATS */
178 # if !defined (ACE_PI_CONTROL_BLOCK_ALIGN_BYTES)
179 # define ACE_PI_CONTROL_BLOCK_ALIGN_BYTES \
180 ACE_MALLOC_ROUNDUP (ACE_PI_CONTROL_BLOCK_SIZE, ACE_MALLOC_ALIGN) - ACE_PI_CONTROL_BLOCK_SIZE
181 # endif /* !ACE_PI_CONTROL_BLOCK_ALIGN_LONGS */
183 char align_
[(ACE_PI_CONTROL_BLOCK_ALIGN_BYTES
) ? ACE_PI_CONTROL_BLOCK_ALIGN_BYTES
: ACE_MALLOC_ALIGN
];
185 /// Dummy node used to anchor the freelist. This needs to come last...
186 ACE_Malloc_Header base_
;
188 /// Dump the state of the object.
189 void dump (void) const;
192 // Disallow assignment.
193 void operator= (const ACE_Control_Block
&);
196 ACE_END_VERSIONED_NAMESPACE_DECL
198 #if defined (__ACE_INLINE__)
199 #include "ace/PI_Malloc.inl"
200 #endif /* __ACE_INLINE__ */
202 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
204 #include /**/ "ace/post.h"
206 #endif /* ACE_PI_MALLOC_H */