Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / OS_Memory.h
blobeec0b65df8f4b5e3f0f60ac1bf3beaaa53f5c203
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file OS_Memory.h
7 * @author Doug Schmidt <d.schmidt@vanderbilt.edu>
8 * @author Jesper S. M|ller<stophph@diku.dk>
9 * @author and a cast of thousands...
11 //=============================================================================
13 #ifndef ACE_OS_MEMORY_H
14 #define ACE_OS_MEMORY_H
15 #include /**/ "ace/pre.h"
17 #include /**/ "ace/ACE_export.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 # pragma once
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #include "ace/OS_Errno.h"
24 #include "ace/Basic_Types.h"
25 #include "ace/os_include/os_stddef.h"
27 // Allow an installation to replace the lowest-level allocation
28 // functions without changing the source of ACE.
30 // To do this, simple #define ACE_*_FUNC macros in config.h to
31 // the names of the site-specific functions, e.g.,
33 // #define ACE_MALLOC_FUNC dlmalloc
34 // #define ACE_CALLOC_FUNC dlcalloc
35 // #define ACE_FREE_FUNC dlfree
36 // #define ACE_REALLOC_FUNC dlrealloc
38 // For completeness' sake, you should probably put
39 // #define ACE_HAS_STRDUP_EMULATION
40 // #define ACE_HAS_WCSDUP_EMULATION
41 // too, so that you guarantee that strdup() and wcsdup() call your
42 // desired mallocator and not the system mallocator.
44 #if !defined (ACE_MALLOC_FUNC)
45 # define ACE_MALLOC_FUNC ::malloc
46 #endif
47 #if !defined (ACE_CALLOC_FUNC)
48 # define ACE_CALLOC_FUNC ::calloc
49 #endif
50 #if !defined (ACE_FREE_FUNC)
51 # define ACE_FREE_FUNC ::free
52 #endif
53 #if !defined (ACE_REALLOC_FUNC)
54 # define ACE_REALLOC_FUNC ::realloc
55 #endif
57 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
59 typedef void * ACE_MALLOC_T;
61 ACE_END_VERSIONED_NAMESPACE_DECL
63 // For backwards compatibility, we except all compilers to support these
64 #include /**/ <new>
65 #define ACE_bad_alloc std::bad_alloc
66 #define ACE_nothrow std::nothrow
67 #define ACE_nothrow_t std::nothrow_t
68 #define ACE_del_bad_alloc
69 #define ACE_throw_bad_alloc throw std::bad_alloc ()
71 // ACE_NEW macros
72 #define ACE_NEW_RETURN(POINTER,CONSTRUCTOR,RET_VAL) \
73 do { POINTER = new (std::nothrow) CONSTRUCTOR; \
74 if (POINTER == nullptr) { errno = ENOMEM; return RET_VAL; } \
75 } while (0)
76 #define ACE_NEW(POINTER,CONSTRUCTOR) \
77 do { POINTER = new(std::nothrow) CONSTRUCTOR; \
78 if (POINTER == nullptr) { errno = ENOMEM; return; } \
79 } while (0)
80 #define ACE_NEW_NORETURN(POINTER,CONSTRUCTOR) \
81 do { POINTER = new(std::nothrow) CONSTRUCTOR; \
82 if (POINTER == nullptr) { errno = ENOMEM; } \
83 } while (0)
85 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
86 //@{
87 /**
88 * @name Efficiently compute aligned pointers to powers of 2 boundaries.
91 /**
92 * Efficiently align "value" up to "alignment", knowing that all such
93 * boundaries are binary powers and that we're using two's complement
94 * arithmetic.
96 * Since the alignment is a power of two its binary representation is:
98 * alignment = 0...010...0
100 * hence
102 * alignment - 1 = 0...001...1 = T1
104 * so the complement is:
106 * ~(alignment - 1) = 1...110...0 = T2
108 * Notice that there is a multiple of @a alignment in the range
109 * [<value>,<value> + T1], also notice that if
111 * X = ( <value> + T1 ) & T2
113 * then
115 * <value> <= X <= <value> + T1
117 * because the & operator only changes the last bits, and since X is a
118 * multiple of @a alignment (its last bits are zero) we have found the
119 * multiple we wanted.
121 /// Return the next integer aligned to a required boundary
123 * @param ptr the base pointer
124 * @param alignment the required alignment
126 inline uintptr_t
127 ACE_align_binary (uintptr_t ptr, uintptr_t alignment)
129 uintptr_t const tmp = alignment - 1;
130 return (ptr + tmp) & (~tmp);
133 /// Return the next address aligned to a required boundary
134 inline char *
135 ACE_ptr_align_binary (char const * ptr, uintptr_t alignment)
137 return
138 reinterpret_cast<char *> (
139 ACE_align_binary (reinterpret_cast<uintptr_t> (ptr), alignment));
142 /// Return the next address aligned to a required boundary
143 inline char *
144 ACE_ptr_align_binary (unsigned char const * ptr, uintptr_t alignment)
146 return
147 ACE_ptr_align_binary (reinterpret_cast<char const *> (ptr), alignment);
149 //@}
150 ACE_END_VERSIONED_NAMESPACE_DECL
152 #include "ace/OS_NS_stdlib.h"
154 #include /**/ "ace/post.h"
155 #endif /* ACE_OS_MEMORY_H */