[6916] Fixed typos in spell checking code.
[getmangos.git] / dep / ACE_wrappers / ace / PI_Malloc.h
blob679b71b98ca8e90e51a4e6173dfac759f46f1f28
1 // -*- C++ -*-
3 //==========================================================================
4 /**
5 * @file PI_Malloc.h
7 * $Id: PI_Malloc.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author Priyanka Gontla <pgontla@ece.uci.edu>
10 * @author Based on code that existed in other ACE files.
12 //==========================================================================
14 #ifndef ACE_PI_MALLOC_H
15 #define ACE_PI_MALLOC_H
17 #include /**/ "ace/pre.h"
19 #include /**/ "ace/ACE_export.h"
21 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 # pragma once
23 #endif /* ACE_LACKS_PRAGMA_ONCE */
25 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
27 #include "ace/Malloc.h"
28 #include "ace/Based_Pointer_T.h"
30 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
32 // prepare for position independent malloc
33 /**
34 * @class ACE_PI_Control_Block
36 * @brief This information is stored in memory allocated by the Memory_Pool.
38 * This class implements the control block structure that can be
39 * used in a "position indepent" fashion, i.e., you don't need to
40 * "map" the underlying memory pool to the same address in
41 * processes sharing the memory. The tradoff of this flexibility
42 * is more expensive malloc/free operations.
44 class ACE_Export ACE_PI_Control_Block
46 public:
47 class ACE_Malloc_Header;
48 class ACE_Name_Node;
50 typedef ACE_Based_Pointer<ACE_Malloc_Header> MALLOC_HEADER_PTR;
51 typedef ACE_Based_Pointer<ACE_Name_Node> NAME_NODE_PTR;
52 typedef ACE_Based_Pointer_Basic<char> CHAR_PTR;
54 /**
55 * @class ACE_Malloc_Header
57 * @brief This is the control block header. It's used by ACE_Malloc
58 * to keep track of each chunk of data when it's in the free
59 * list or in use.
61 class ACE_Export ACE_Malloc_Header
63 public:
64 ACE_Malloc_Header (void);
66 /// Points to next block if on free list.
67 MALLOC_HEADER_PTR next_block_;
69 /// Initialize a malloc header pointer.
70 static void init_ptr (MALLOC_HEADER_PTR *ptr,
71 ACE_Malloc_Header *init,
72 void *base_addr);
74 /// Size of this header control block.
75 size_t size_;
77 # if !defined (ACE_PI_MALLOC_PADDING_SIZE)
78 # 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))
79 # endif /* !ACE_PI_MALLOC_PADDING_SIZE */
80 char padding_[(ACE_PI_MALLOC_PADDING_SIZE) ? ACE_PI_MALLOC_PADDING_SIZE : ACE_MALLOC_ALIGN];
82 /// Dump the state of the object.
83 void dump (void) const;
85 private:
87 // Disallow copy construction and assignment.
88 ACE_Malloc_Header (ACE_Malloc_Header const &);
89 void operator= (ACE_Malloc_Header const &);
93 /**
94 * @class ACE_Name_Node
96 * @brief This class supports "named memory regions" within ACE_Malloc.
98 * Internally, the named memory regions are stored as a
99 * doubly-linked list within the Memory_Pool. This makes
100 * it easy to iterate over the items in the list in both FIFO
101 * and LIFO order.
103 class ACE_Export ACE_Name_Node
105 public:
106 // = Initialization methods.
107 /// Constructor.
108 ACE_Name_Node (const char *name,
109 char *name_ptr,
110 char *pointer,
111 ACE_Name_Node *head);
113 /// Copy constructor.
114 ACE_Name_Node (const ACE_Name_Node &);
116 /// Constructor.
117 ACE_Name_Node (void);
119 /// Constructor.
120 ~ACE_Name_Node (void);
122 /// Initialize a name node pointer.
123 static void init_ptr (NAME_NODE_PTR *ptr,
124 ACE_Name_Node *init,
125 void *base_addr);
127 /// Return a pointer to the name of this node.
128 const char *name (void) const;
130 /// Assign a name;
131 void name (const char *);
133 /// Name of the Node.
134 CHAR_PTR name_;
136 /// Pointer to the contents.
137 CHAR_PTR pointer_;
139 /// Pointer to the next node in the doubly-linked list.
140 NAME_NODE_PTR next_;
142 /// Pointer to the previous node in the doubly-linked list.
143 NAME_NODE_PTR prev_;
145 /// Dump the state of the object.
146 void dump (void) const;
148 private:
150 // Disallow assignment.
151 void operator= (const ACE_Name_Node &);
154 /// Print out a bunch of size info for debugging.
155 static void print_alignment_info (void);
157 /// Reference counter.
158 int ref_counter_;
160 /// Head of the linked list of Name Nodes.
161 NAME_NODE_PTR name_head_;
163 /// Current head of the freelist.
164 MALLOC_HEADER_PTR freep_;
166 /// Name of lock thats ensures mutual exclusion.
167 char lock_name_[MAXNAMELEN];
169 #if defined (ACE_HAS_MALLOC_STATS)
170 /// Keep statistics about ACE_Malloc state and performance.
171 ACE_Malloc_Stats malloc_stats_;
172 #define ACE_PI_CONTROL_BLOCK_SIZE ((int)(sizeof (NAME_NODE_PTR) \
173 + sizeof (MALLOC_HEADER_PTR) \
174 + sizeof (int) \
175 + MAXNAMELEN \
176 + sizeof (ACE_Malloc_Stats)))
177 #else
178 #define ACE_PI_CONTROL_BLOCK_SIZE ((int)(sizeof (NAME_NODE_PTR) \
179 + sizeof (MALLOC_HEADER_PTR) \
180 + sizeof (int) \
181 + MAXNAMELEN))
182 #endif /* ACE_HAS_MALLOC_STATS */
184 # if !defined (ACE_PI_CONTROL_BLOCK_ALIGN_BYTES)
185 # define ACE_PI_CONTROL_BLOCK_ALIGN_BYTES \
186 ACE_MALLOC_ROUNDUP (ACE_PI_CONTROL_BLOCK_SIZE, ACE_MALLOC_ALIGN) - ACE_PI_CONTROL_BLOCK_SIZE
187 # endif /* !ACE_PI_CONTROL_BLOCK_ALIGN_LONGS */
188 /// Force alignment.
189 char align_[(ACE_PI_CONTROL_BLOCK_ALIGN_BYTES) ? ACE_PI_CONTROL_BLOCK_ALIGN_BYTES : ACE_MALLOC_ALIGN];
191 /// Dummy node used to anchor the freelist. This needs to come last...
192 ACE_Malloc_Header base_;
194 /// Dump the state of the object.
195 void dump (void) const;
197 private:
199 // Disallow assignment.
200 void operator= (const ACE_Control_Block &);
203 ACE_END_VERSIONED_NAMESPACE_DECL
205 #if defined (__ACE_INLINE__)
206 #include "ace/PI_Malloc.inl"
207 #endif /* __ACE_INLINE__ */
209 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
211 #include /**/ "ace/post.h"
213 #endif /* ACE_PI_MALLOC_H */