Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

PI_Malloc.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //==========================================================================
00004 /**
00005  *  @file   PI_Malloc.h
00006  *
00007  *  $Id: PI_Malloc.h,v 1.1.1.2 2003/02/21 18:36:32 chad Exp $
00008  *
00009  *  @author Priyanka Gontla <pgontla@ece.uci.edu>
00010  *  @author Based on code that existed in other ACE files.
00011  */
00012 //==========================================================================
00013 
00014 #ifndef ACE_PI_MALLOC_H
00015 #define ACE_PI_MALLOC_H
00016 
00017 #include "ace/pre.h"
00018 
00019 #include "ace/ACE_export.h"
00020 
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 # pragma once
00023 #endif /* ACE_LACKS_PRAGMA_ONCE */
00024 
00025 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
00026 
00027 #include "ace/Malloc.h"
00028 #include "ace/Based_Pointer_T.h"
00029 
00030 // prepare for position independent malloc
00031 /**
00032  * @class ACE_PI_Control_Block
00033  *
00034  * @brief This information is stored in memory allocated by the <Memory_Pool>.
00035  *
00036  * This class implements the control block structure that can be
00037  * used in a "position indepent" fashion, i.e., you don't need to
00038  * "map" the underlying memory pool to the same address in
00039  * processes sharing the memory.  The tradoff of this flexibility
00040  * is more expensive malloc/free operations.
00041  */
00042 class ACE_Export ACE_PI_Control_Block
00043 {
00044 public:
00045   class ACE_Malloc_Header;
00046   class ACE_Name_Node;
00047 
00048   typedef ACE_Based_Pointer<ACE_Malloc_Header> MALLOC_HEADER_PTR;
00049   typedef ACE_Based_Pointer<ACE_Name_Node> NAME_NODE_PTR;
00050   typedef ACE_Based_Pointer_Basic<char> CHAR_PTR;
00051 
00052   /**
00053    * @class ACE_Malloc_Header
00054    *
00055    * @brief This is the control block header.  It's used by <ACE_Malloc>
00056    * to keep track of each chunk of data when it's in the free
00057    * list or in use.
00058    */
00059   class ACE_Export ACE_Malloc_Header
00060   {
00061   public:
00062     ACE_Malloc_Header (void);
00063 
00064     /// Points to next block if on free list.
00065     MALLOC_HEADER_PTR next_block_;
00066 
00067     /// Initialize a malloc header pointer.
00068     static void init_ptr (MALLOC_HEADER_PTR *ptr,
00069                           ACE_Malloc_Header *init,
00070                           void *base_addr);
00071 
00072     /// Size of this header control block.
00073     size_t size_;
00074 
00075 #if defined (ACE_PI_MALLOC_PADDING_SIZE) && (ACE_PI_MALLOC_PADDING_SIZE == 0)
00076     // No padding required for PI_Malloc_Header.
00077 #else
00078 # if !defined (ACE_PI_MALLOC_PADDING_SIZE)
00079 #   define ACE_PI_MALLOC_PADDING_SIZE ((int) (ACE_MALLOC_HEADER_SIZE - \
00080                                        (sizeof (MALLOC_HEADER_PTR) + sizeof (size_t)))\
00081                                        / (int) sizeof (long))
00082 # endif /* !ACE_PI_MALLOC_PADDING_SIZE */
00083     long padding_[ACE_PI_MALLOC_PADDING_SIZE < 1 ? 1 : ACE_PI_MALLOC_PADDING_SIZE];
00084 #endif /* ACE_PI_MALLOC_PADDING_SIZE && ACE_PI_MALLOC_PADDING_SIZE == 0 */
00085 
00086     /// Dump the state of the object.
00087     void dump (void) const;
00088 
00089   private:
00090     ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Malloc_Header &))
00091   };
00092 
00093   /**
00094    * @class ACE_Name_Node
00095    *
00096    * @brief This class supports "named memory regions" within <ACE_Malloc>.
00097    *
00098    * Internally, the named memory regions are stored as a
00099    * doubly-linked list within the <Memory_Pool>.  This makes
00100    * it easy to iterate over the items in the list in both FIFO
00101    * and LIFO order.
00102    */
00103   class ACE_Export ACE_Name_Node
00104   {
00105   public:
00106     // = Initialization methods.
00107     /// Constructor.
00108     ACE_Name_Node (const char *name,
00109                    char *name_ptr,
00110                    char *pointer,
00111                    ACE_Name_Node *head);
00112 
00113     /// Copy constructor.
00114     ACE_Name_Node (const ACE_Name_Node &);
00115 
00116     /// Constructor.
00117     ACE_Name_Node (void);
00118 
00119     /// Constructor.
00120     ~ACE_Name_Node (void);
00121 
00122     /// Initialize a name node pointer.
00123     static void init_ptr (NAME_NODE_PTR *ptr,
00124                           ACE_Name_Node *init,
00125                           void *base_addr);
00126 
00127     /// Return a pointer to the name of this node.
00128     const char *name (void) const;
00129 
00130     /// Assign a name;
00131     void name (const char *);
00132 
00133     /// Name of the Node.
00134     CHAR_PTR name_;
00135 
00136     /// Pointer to the contents.
00137     CHAR_PTR pointer_;
00138 
00139     /// Pointer to the next node in the doubly-linked list.
00140     NAME_NODE_PTR next_;
00141 
00142     /// Pointer to the previous node in the doubly-linked list.
00143     NAME_NODE_PTR prev_;
00144 
00145     /// Dump the state of the object.
00146     void dump (void) const;
00147 
00148   private:
00149     ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Name_Node &))
00150   };
00151 
00152   /// Print out a bunch of size info for debugging.
00153   static void print_alignment_info (void);
00154 
00155   /// Reference counter.
00156   int ref_counter_;
00157 
00158   /// Head of the linked list of Name Nodes.
00159   NAME_NODE_PTR name_head_;
00160 
00161   /// Current head of the freelist.
00162   MALLOC_HEADER_PTR freep_;
00163 
00164   /// Name of lock thats ensures mutual exclusion.
00165   char lock_name_[MAXNAMELEN];
00166 
00167 #if defined (ACE_HAS_MALLOC_STATS)
00168   /// Keep statistics about ACE_Malloc state and performance.
00169   ACE_Malloc_Stats malloc_stats_;
00170 #define ACE_PI_CONTROL_BLOCK_SIZE ((int)(sizeof (NAME_NODE_PTR) \
00171                                          + sizeof (MALLOC_HEADER_PTR) \
00172                                          + sizeof (int) \
00173                                          + MAXNAMELEN  \
00174                                          + sizeof (ACE_Malloc_Stats)))
00175 #else
00176 #define ACE_PI_CONTROL_BLOCK_SIZE ((int)(sizeof (NAME_NODE_PTR) \
00177                                          + sizeof (MALLOC_HEADER_PTR) \
00178                                          + sizeof (int) \
00179                                          + MAXNAMELEN))
00180 #endif /* ACE_HAS_MALLOC_STATS */
00181 
00182 #if defined (ACE_PI_CONTROL_BLOCK_ALIGN_LONGS) && (ACE_PI_CONTROL_BLOCK_ALIGN_LONGS == 0)
00183   // No padding required for PI_Control_Block.
00184 #else
00185 # if !defined (ACE_PI_CONTROL_BLOCK_ALIGN_LONGS)
00186 // Notice the casting to int for <sizeof> otherwise unsigned int
00187 // arithmetic is used and some awful things may happen.
00188 #   define ACE_PI_CONTROL_BLOCK_ALIGN_LONGS \
00189             ((ACE_PI_CONTROL_BLOCK_SIZE % ACE_MALLOC_ALIGN != 0 \
00190               ? ACE_MALLOC_ALIGN - (ACE_PI_CONTROL_BLOCK_SIZE % ACE_MALLOC_ALIGN) \
00191               : ACE_MALLOC_ALIGN) / int (sizeof (long)))
00192 # endif /* !ACE_PI_CONTROL_BLOCK_ALIGN_LONGS */
00193   /// Force alignment.
00194   long align_[ACE_PI_CONTROL_BLOCK_ALIGN_LONGS < 1 ? 1 : ACE_PI_CONTROL_BLOCK_ALIGN_LONGS];
00195 #endif /* ACE_PI_CONTROL_BLOCK_ALIGN_LONGS && ACE_PI_CONTROL_BLOCK_ALIGN_LONGS == 0 */
00196 
00197   /// Dummy node used to anchor the freelist.  This needs to come last...
00198   ACE_Malloc_Header base_;
00199 
00200   /// Dump the state of the object.
00201   void dump (void) const;
00202 
00203 private:
00204   ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Control_Block &))
00205 };
00206 
00207 #if defined (__ACE_INLINE__)
00208 #include "ace/PI_Malloc.i"
00209 #endif /* __ACE_INLINE__ */
00210 
00211 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
00212 
00213 #include "ace/post.h"
00214 
00215 #endif /* ACE_PI_MALLOC_H */

Generated on Mon Jun 16 11:20:48 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002