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

OS_Memory.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file   OS_Memory.h
00006  *
00007  *  $Id: OS_Memory.h,v 1.1.1.3 2003/02/21 18:36:32 chad Exp $
00008  *
00009  *  @author Doug Schmidt <schmidt@cs.wustl.edu>
00010  *  @author Jesper S. M|ller<stophph@diku.dk>
00011  *  @author and a cast of thousands...
00012  */
00013 //=============================================================================
00014 
00015 #ifndef ACE_OS_MEMORY_H
00016 #define ACE_OS_MEMORY_H
00017 #include "ace/pre.h"
00018 
00019 #include "ace/OS_Export.h"
00020 
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 # pragma once
00023 #endif /* ACE_LACKS_PRAGMA_ONCE */
00024 
00025 #include "ace/OS_Errno.h"
00026 
00027 #ifndef ACE_HAS_WINCE
00028 #include <stddef.h>
00029 #endif  // ACE_HAS_WINCE
00030 
00031 # if !defined (ACE_MALLOC_ALIGN)
00032 #   define ACE_MALLOC_ALIGN ((int) sizeof (long))
00033 # endif /* ACE_MALLOC_ALIGN */
00034 
00035 // Allow an installation to replace the lowest-level allocation
00036 // functions without changing the source of ACE.
00037 //
00038 // To do this, simple #define ACE_*_FUNC macros in config.h to
00039 // the names of the site-specific functions, e.g.,
00040 //
00041 //   #define ACE_MALLOC_FUNC  dlmalloc
00042 //   #define ACE_CALLOC_FUNC  dlcalloc
00043 //   #define ACE_FREE_FUNC    dlfree
00044 //   #define ACE_REALLOC_FUNC dlrealloc
00045 //
00046 // For completeness' sake, you should probably put
00047 //   #define ACE_HAS_STRDUP_EMULATION
00048 // too, so that you guarantee that strdup() calls your desired mallocator
00049 // and not the system mallocator.
00050 //
00051 #if !defined (ACE_MALLOC_FUNC)
00052 #  define ACE_MALLOC_FUNC ::malloc
00053 #endif
00054 #if !defined (ACE_CALLOC_FUNC)
00055 #  define ACE_CALLOC_FUNC ::calloc
00056 #endif
00057 #if !defined (ACE_FREE_FUNC)
00058 #  define ACE_FREE_FUNC ::free
00059 #endif
00060 #if !defined (ACE_REALLOC_FUNC)
00061 #  define ACE_REALLOC_FUNC ::realloc
00062 #endif
00063 
00064 #if defined (ACE_HAS_OLD_MALLOC)
00065 typedef char *ACE_MALLOC_T;
00066 #else
00067 typedef void *ACE_MALLOC_T;
00068 #endif /* ACE_HAS_OLD_MALLOC */
00069 
00070 // ============================================================================
00071 // ACE_NEW macros
00072 //
00073 // A useful abstraction for expressions involving operator new since
00074 // we can change memory allocation error handling policies (e.g.,
00075 // depending on whether ANSI/ISO exception handling semantics are
00076 // being used).
00077 // ============================================================================
00078 
00079 #if defined (ACE_NEW_THROWS_EXCEPTIONS)
00080 
00081 // Since new() throws exceptions, we need a way to avoid passing
00082 // exceptions past the call to new because ACE counts on having a 0
00083 // return value for a failed allocation. Some compilers offer the
00084 // new (nothrow) version, which does exactly what we want. Others
00085 // do not. For those that do not, this sets up what exception is thrown,
00086 // and then below we'll do a try/catch around the new to catch it and
00087 // return a 0 pointer instead.
00088 
00089 #  if defined (__HP_aCC)
00090       // I know this works for HP aC++... if <stdexcept> is used, it
00091       // introduces other stuff that breaks things, like <memory>, which
00092       // screws up auto_ptr.
00093 #    include /**/ <new>
00094     // _HP_aCC was first defined at aC++ 03.13 on HP-UX 11. Prior to that
00095     // (03.10 and before) a failed new threw bad_alloc. After that (03.13
00096     // and above) the exception thrown is dependent on the below settings.
00097 #    if (HPUX_VERS >= 1100)
00098 #      if ((__HP_aCC < 32500 && !defined (RWSTD_NO_NAMESPACE)) || \
00099            defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB))
00100 #        define ACE_bad_alloc std::bad_alloc
00101 #        define ACE_nothrow   std::nothrow
00102 #        define ACE_nothrow_t std::nothrow_t
00103 #      else
00104 #        define ACE_bad_alloc bad_alloc
00105 #        define ACE_nothrow   nothrow
00106 #        define ACE_nothrow_t nothrow_t
00107 #      endif /* __HP_aCC */
00108 #    elif ((__HP_aCC <  12500 && !defined (RWSTD_NO_NAMESPACE)) || \
00109            defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB))
00110 #      define ACE_bad_alloc std::bad_alloc
00111 #      define ACE_nothrow   std::nothrow
00112 #      define ACE_nothrow_t std::nothrow_t
00113 #    else
00114 #      define ACE_bad_alloc bad_alloc
00115 #      define ACE_nothrow   nothrow
00116 #      define ACE_nothrow_t nothrow_t
00117 #    endif /* HPUX_VERS < 1100 */
00118 #    define ACE_throw_bad_alloc throw ACE_bad_alloc ()
00119 #  elif defined (__SUNPRO_CC)
00120 #      if (__SUNPRO_CC < 0x500) || (__SUNPRO_CC_COMPAT == 4)
00121 #        include /**/ <exception.h>
00122          // Note: we catch ::xalloc rather than just xalloc because of
00123          // a name clash with unsafe_ios::xalloc()
00124 #        define ACE_bad_alloc ::xalloc
00125 #        define ACE_throw_bad_alloc throw ACE_bad_alloc ("no more memory")
00126 #      else
00127 #        include /**/ <new>
00128 #        define ACE_bad_alloc std::bad_alloc
00129 #        define ACE_throw_bad_alloc throw ACE_bad_alloc ()
00130 #      endif /* __SUNPRO_CC < 0x500 */
00131 #  elif defined (__BORLANDC__) || defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB)
00132 #    include /**/ <new>
00133 #    define ACE_bad_alloc std::bad_alloc
00134 #    define ACE_throw_bad_alloc throw ACE_bad_alloc ()
00135 #  else
00136 #    include /**/ <new>
00137 #    define ACE_bad_alloc bad_alloc
00138 #    define ACE_throw_bad_alloc throw ACE_bad_alloc ()
00139 #  endif /* __HP_aCC */
00140 
00141 #  if defined (ACE_HAS_NEW_NOTHROW)
00142 #    define ACE_NEW_RETURN(POINTER,CONSTRUCTOR,RET_VAL) \
00143    do { POINTER = new (ACE_nothrow) CONSTRUCTOR; \
00144      if (POINTER == 0) { errno = ENOMEM; return RET_VAL; } \
00145    } while (0)
00146 #    define ACE_NEW(POINTER,CONSTRUCTOR) \
00147    do { POINTER = new(ACE_nothrow) CONSTRUCTOR; \
00148      if (POINTER == 0) { errno = ENOMEM; return; } \
00149    } while (0)
00150 #    define ACE_NEW_NORETURN(POINTER,CONSTRUCTOR) \
00151    do { POINTER = new(ACE_nothrow) CONSTRUCTOR; \
00152      if (POINTER == 0) { errno = ENOMEM; } \
00153    } while (0)
00154 
00155 #  else
00156 
00157 #    define ACE_NEW_RETURN(POINTER,CONSTRUCTOR,RET_VAL) \
00158    do { try { POINTER = new CONSTRUCTOR; } \
00159         catch (ACE_bad_alloc) { errno = ENOMEM; POINTER = 0; return RET_VAL; } \
00160    } while (0)
00161 
00162 #    define ACE_NEW(POINTER,CONSTRUCTOR) \
00163    do { try { POINTER = new CONSTRUCTOR; } \
00164         catch (ACE_bad_alloc) { errno = ENOMEM; POINTER = 0; return; } \
00165    } while (0)
00166 
00167 #    define ACE_NEW_NORETURN(POINTER,CONSTRUCTOR) \
00168    do { try { POINTER = new CONSTRUCTOR; } \
00169         catch (ACE_bad_alloc) { errno = ENOMEM; POINTER = 0; } \
00170    } while (0)
00171 #  endif /* ACE_HAS_NEW_NOTHROW */
00172 
00173 #else /* ACE_NEW_THROWS_EXCEPTIONS */
00174 
00175 # define ACE_NEW_RETURN(POINTER,CONSTRUCTOR,RET_VAL) \
00176    do { POINTER = new CONSTRUCTOR; \
00177      if (POINTER == 0) { errno = ENOMEM; return RET_VAL; } \
00178    } while (0)
00179 # define ACE_NEW(POINTER,CONSTRUCTOR) \
00180    do { POINTER = new CONSTRUCTOR; \
00181      if (POINTER == 0) { errno = ENOMEM; return; } \
00182    } while (0)
00183 # define ACE_NEW_NORETURN(POINTER,CONSTRUCTOR) \
00184    do { POINTER = new CONSTRUCTOR; \
00185      if (POINTER == 0) { errno = ENOMEM; } \
00186    } while (0)
00187 
00188 # define ACE_throw_bad_alloc \
00189   void* gcc_will_complain_if_literal_0_is_returned = 0; \
00190   return gcc_will_complain_if_literal_0_is_returned
00191 
00192 #endif /* ACE_NEW_THROWS_EXCEPTIONS */
00193 
00194 /**
00195  * @class ACE_OS_Memory
00196  *
00197  * @brief This class is a wrapper for dynamic memory operations.
00198  *
00199  */
00200 class ACE_OS_Export ACE_OS_Memory
00201 {
00202 public:
00203   // = A set of wrappers for memory managment.
00204   static void *sbrk (int brk);
00205   static void *calloc (size_t elements, size_t sizeof_elements);
00206   static void *malloc (size_t);
00207   static void *realloc (void *, size_t);
00208   static void free (void *);
00209 };
00210 
00211 # if defined (ACE_HAS_INLINED_OSCALLS)
00212 #   if defined (ACE_INLINE)
00213 #     undef ACE_INLINE
00214 #   endif /* ACE_INLINE */
00215 #   define ACE_INLINE inline
00216 #   include "ace/OS_Memory.inl"
00217 # endif /* ACE_HAS_INLINED_OSCALLS */
00218 
00219 #include "ace/post.h"
00220 #endif /* ACE_OS_MEMORY_H */

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