00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 #ifndef ACE_OS_MEMORY_H
00016 #define ACE_OS_MEMORY_H
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 
00024 
00025 #include "ace/OS_Errno.h"
00026 #include "ace/os_include/os_stddef.h"
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 #if !defined (ACE_MALLOC_FUNC)
00046 #  define ACE_MALLOC_FUNC ::malloc
00047 #endif
00048 #if !defined (ACE_CALLOC_FUNC)
00049 #  define ACE_CALLOC_FUNC ::calloc
00050 #endif
00051 #if !defined (ACE_FREE_FUNC)
00052 #  define ACE_FREE_FUNC ::free
00053 #endif
00054 #if !defined (ACE_REALLOC_FUNC)
00055 #  define ACE_REALLOC_FUNC ::realloc
00056 #endif
00057 
00058 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00059 
00060 #if defined (ACE_HAS_OLD_MALLOC)
00061 typedef char * ACE_MALLOC_T;
00062 #else
00063 typedef void * ACE_MALLOC_T;
00064 #endif 
00065 
00066 ACE_END_VERSIONED_NAMESPACE_DECL
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 #if defined (ACE_HAS_NEW_NOTHROW)
00079 #  if !defined (ACE_NEW_THROWS_EXCEPTIONS)
00080 #    define ACE_NEW_THROWS_EXCEPTIONS
00081 #  endif
00082 #endif
00083 
00084 #if defined (ACE_NEW_THROWS_EXCEPTIONS)
00085 
00086 
00087 
00088 
00089 
00090 
00091 
00092 
00093 
00094 #  if defined (__HP_aCC)
00095       
00096       
00097       
00098 #    include  <new>
00099     
00100     
00101     
00102 #    if (HPUX_VERS >= 1100)
00103 #      if ((__HP_aCC < 32500 && !defined (RWSTD_NO_NAMESPACE)) || \
00104            defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB))
00105 #        define ACE_bad_alloc std::bad_alloc
00106 #        define ACE_nothrow   std::nothrow
00107 #        define ACE_nothrow_t std::nothrow_t
00108 #      else
00109 #        define ACE_bad_alloc bad_alloc
00110 #        define ACE_nothrow   nothrow
00111 #        define ACE_nothrow_t nothrow_t
00112 #      endif 
00113 #    elif ((__HP_aCC <  12500 && !defined (RWSTD_NO_NAMESPACE)) || \
00114            defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB))
00115 #      define ACE_bad_alloc std::bad_alloc
00116 #      define ACE_nothrow   std::nothrow
00117 #      define ACE_nothrow_t std::nothrow_t
00118 #    else
00119 #      define ACE_bad_alloc bad_alloc
00120 #      define ACE_nothrow   nothrow
00121 #      define ACE_nothrow_t nothrow_t
00122 #    endif 
00123 #    define ACE_throw_bad_alloc throw ACE_bad_alloc ()
00124 #  elif defined (__SUNPRO_CC)
00125 #      if (__SUNPRO_CC < 0x500) || (__SUNPRO_CC_COMPAT == 4)
00126 #        include  <exception.h>
00127          
00128          
00129 #        define ACE_bad_alloc ::xalloc
00130 #        define ACE_throw_bad_alloc throw ACE_bad_alloc ("no more memory")
00131 #      else
00132 #        include  <new>
00133 #        define ACE_bad_alloc std::bad_alloc
00134 #        if defined (ACE_HAS_NEW_NOTHROW)
00135 #          if defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB)
00136 #            define ACE_nothrow   std::nothrow
00137 #            define ACE_nothrow_t std::nothrow_t
00138 #          else
00139 #            define ACE_nothrow   nothrow
00140 #            define ACE_nothrow_t nothrow_t
00141 #          endif 
00142 #        endif 
00143 #        define ACE_throw_bad_alloc throw ACE_bad_alloc ()
00144 #      endif 
00145 #  elif defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB)
00146 #    include  <new>
00147 #    if !defined (ACE_bad_alloc)
00148 #      define ACE_bad_alloc std::bad_alloc
00149 #    endif
00150 #    define ACE_nothrow   std::nothrow
00151 #    define ACE_nothrow_t std::nothrow_t
00152 #    define ACE_throw_bad_alloc throw ACE_bad_alloc ()
00153 #  else
00154 #    include  <new>
00155 #    if !defined (ACE_bad_alloc)
00156 #      define ACE_bad_alloc bad_alloc
00157 #    endif
00158 #    define ACE_nothrow   nothrow
00159 #    define ACE_nothrow_t nothrow_t
00160 #    define ACE_throw_bad_alloc throw ACE_bad_alloc ()
00161 #  endif 
00162 
00163 #  if defined (ACE_HAS_NEW_NOTHROW)
00164 #    define ACE_NEW_RETURN(POINTER,CONSTRUCTOR,RET_VAL) \
00165    do { POINTER = new (ACE_nothrow) CONSTRUCTOR; \
00166      if (POINTER == 0) { errno = ENOMEM; return RET_VAL; } \
00167    } while (0)
00168 #    define ACE_NEW(POINTER,CONSTRUCTOR) \
00169    do { POINTER = new(ACE_nothrow) CONSTRUCTOR; \
00170      if (POINTER == 0) { errno = ENOMEM; return; } \
00171    } while (0)
00172 #    define ACE_NEW_NORETURN(POINTER,CONSTRUCTOR) \
00173    do { POINTER = new(ACE_nothrow) CONSTRUCTOR; \
00174      if (POINTER == 0) { errno = ENOMEM; } \
00175    } while (0)
00176 
00177 #  else
00178 
00179 #    define ACE_NEW_RETURN(POINTER,CONSTRUCTOR,RET_VAL) \
00180    do { try { POINTER = new CONSTRUCTOR; } \
00181         catch (ACE_bad_alloc) { errno = ENOMEM; POINTER = 0; return RET_VAL; } \
00182    } while (0)
00183 
00184 #    define ACE_NEW(POINTER,CONSTRUCTOR) \
00185    do { try { POINTER = new CONSTRUCTOR; } \
00186         catch (ACE_bad_alloc) { errno = ENOMEM; POINTER = 0; return; } \
00187    } while (0)
00188 
00189 #    define ACE_NEW_NORETURN(POINTER,CONSTRUCTOR) \
00190    do { try { POINTER = new CONSTRUCTOR; } \
00191         catch (ACE_bad_alloc) { errno = ENOMEM; POINTER = 0; } \
00192    } while (0)
00193 #  endif 
00194 
00195 #else 
00196 
00197 # define ACE_NEW_RETURN(POINTER,CONSTRUCTOR,RET_VAL) \
00198    do { POINTER = new CONSTRUCTOR; \
00199      if (POINTER == 0) { errno = ENOMEM; return RET_VAL; } \
00200    } while (0)
00201 # define ACE_NEW(POINTER,CONSTRUCTOR) \
00202    do { POINTER = new CONSTRUCTOR; \
00203      if (POINTER == 0) { errno = ENOMEM; return; } \
00204    } while (0)
00205 # define ACE_NEW_NORETURN(POINTER,CONSTRUCTOR) \
00206    do { POINTER = new CONSTRUCTOR; \
00207      if (POINTER == 0) { errno = ENOMEM; } \
00208    } while (0)
00209 
00210 # define ACE_throw_bad_alloc \
00211   void* gcc_will_complain_if_literal_0_is_returned = 0; \
00212   return gcc_will_complain_if_literal_0_is_returned
00213 
00214 #endif 
00215 
00216 
00217 
00218 
00219 
00220 
00221 
00222 
00223 
00224 
00225 
00226 
00227 
00228 
00229 
00230 
00231 
00232 
00233 
00234 
00235 
00236 
00237 
00238 
00239 
00240 
00241 
00242 
00243 
00244 
00245 
00246 
00247 
00248 
00249 
00250 
00251 
00252 
00253 
00254 
00255 
00256 #define ACE_align_binary(ptr, alignment) \
00257     ((ptr + ((ptrdiff_t)((alignment)-1))) & (~((ptrdiff_t)((alignment)-1))))
00258 
00259 
00260 #define ACE_ptr_align_binary(ptr, alignment) \
00261         ((char *) ACE_align_binary (((ptrdiff_t) (ptr)), (alignment)))
00262 
00263 
00264 #include "ace/OS_NS_stdlib.h"
00265 
00266 #include  "ace/post.h"
00267 #endif