scalable_allocator.h Source File

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# scalable_allocator.h

Go to the documentation of this file.

    00001 /*
    00002     Copyright 2005-2010 Intel Corporation.  All Rights Reserved.
    00003
    00004     The source code contained or described herein and all documents related
    00005     to the source code ("Material") are owned by Intel Corporation or its
    00006     suppliers or licensors.  Title to the Material remains with Intel
    00007     Corporation or its suppliers and licensors.  The Material is protected
    00008     by worldwide copyright laws and treaty provisions.  No part of the
    00009     Material may be used, copied, reproduced, modified, published, uploaded,
    00010     posted, transmitted, distributed, or disclosed in any way without
    00011     Intel's prior express written permission.
    00012
    00013     No license under any patent, copyright, trade secret or other
    00014     intellectual property right is granted to or conferred upon you by
    00015     disclosure or delivery of the Materials, either expressly, by
    00016     implication, inducement, estoppel or otherwise.  Any license under such
    00017     intellectual property rights must be express and approved by Intel in
    00018     writing.
    00019 */
    00020
    00021 #ifndef __TBB_scalable_allocator_H
    00022 #define __TBB_scalable_allocator_H
    00023
    00025 #include <stddef.h> /* Need ptrdiff_t and size_t from here. */
    00026
    00027 #if !defined(__cplusplus) && __ICC==1100
    00028     #pragma warning (push)
    00029     #pragma warning (disable: 991)
    00030 #endif
    00031
    00032 #ifdef __cplusplus
    00033 extern "C" {
    00034 #endif /* __cplusplus */
    00035
    00036 #if _MSC_VER >= 1400
    00037 #define __TBB_EXPORTED_FUNC   __cdecl
    00038 #else
    00039 #define __TBB_EXPORTED_FUNC
    00040 #endif
    00041
    00044 void * __TBB_EXPORTED_FUNC scalable_malloc (size_t size);
    00045
    00048 void   __TBB_EXPORTED_FUNC scalable_free (void* ptr);
    00049
    00052 void * __TBB_EXPORTED_FUNC scalable_realloc (void* ptr, size_t size);
    00053
    00056 void * __TBB_EXPORTED_FUNC scalable_calloc (size_t nobj, size_t size);
    00057
    00060 int __TBB_EXPORTED_FUNC scalable_posix_memalign (void** memptr, size_t alignment, size_t size);
    00061
    00064 void * __TBB_EXPORTED_FUNC scalable_aligned_malloc (size_t size, size_t alignment);
    00065
    00068 void * __TBB_EXPORTED_FUNC scalable_aligned_realloc (void* ptr, size_t size, size_t alignment);
    00069
    00072 void __TBB_EXPORTED_FUNC scalable_aligned_free (void* ptr);
    00073
    00078 size_t __TBB_EXPORTED_FUNC scalable_msize (void* ptr);
    00079
    00080 #ifdef __cplusplus
    00081 } /* extern "C" */
    00082 #endif /* __cplusplus */
    00083
    00084 #ifdef __cplusplus
    00085
    00086 #include <new>      /* To use new with the placement argument */
    00087
    00088 /* Ensure that including this header does not cause implicit linkage with TBB */
    00089 #ifndef __TBB_NO_IMPLICIT_LINKAGE
    00090     #define __TBB_NO_IMPLICIT_LINKAGE 1
    00091     #include "tbb_stddef.h"
    00092     #undef  __TBB_NO_IMPLICIT_LINKAGE
    00093 #else
    00094     #include "tbb_stddef.h"
    00095 #endif
    00096
    00097
    00098 namespace tbb {
    00099
    00100 #if _MSC_VER && !defined(__INTEL_COMPILER)
    00101     // Workaround for erroneous "unreferenced parameter" warning in method destroy.
    00102     #pragma warning (push)
    00103     #pragma warning (disable: 4100)
    00104 #endif
    00105
    00107
    00110 template<typename T>
    00111 class scalable_allocator {
    00112 public:
    00113     typedef typename internal::allocator_type<T>::value_type value_type;
    00114     typedef value_type* pointer;
    00115     typedef const value_type* const_pointer;
    00116     typedef value_type& reference;
    00117     typedef const value_type& const_reference;
    00118     typedef size_t size_type;
    00119     typedef ptrdiff_t difference_type;
    00120     template<class U> struct rebind {
    00121         typedef scalable_allocator<U> other;
    00122     };
    00123
    00124     scalable_allocator() throw() {}
    00125     scalable_allocator( const scalable_allocator& ) throw() {}
    00126     template<typename U> scalable_allocator(const scalable_allocator<U>&) throw() {}
    00127
    00128     pointer address(reference x) const {return &x;}
    00129     const_pointer address(const_reference x) const {return &x;}
    00130
    00132     pointer allocate( size_type n, const void* /*hint*/ =0 ) {
    00133         return static_cast<pointer>( scalable_malloc( n * sizeof(value_type) ) );
    00134     }
    00135
    00137     void deallocate( pointer p, size_type ) {
    00138         scalable_free( p );
    00139     }
    00140
    00142     size_type max_size() const throw() {
    00143         size_type absolutemax = static_cast<size_type>(-1) / sizeof (value_type);
    00144         return (absolutemax > 0 ? absolutemax : 1);
    00145     }
    00146     void construct( pointer p, const value_type& value ) {::new((void*)(p)) value_type(value);}
    00147     void destroy( pointer p ) {p->~value_type();}
    00148 };
    00149
    00150 #if _MSC_VER && !defined(__INTEL_COMPILER)
    00151     #pragma warning (pop)
    00152 #endif // warning 4100 is back
    00153
    00155
    00156 template<>
    00157 class scalable_allocator<void> {
    00158 public:
    00159     typedef void* pointer;
    00160     typedef const void* const_pointer;
    00161     typedef void value_type;
    00162     template<class U> struct rebind {
    00163         typedef scalable_allocator<U> other;
    00164     };
    00165 };
    00166
    00167 template<typename T, typename U>
    00168 inline bool operator==( const scalable_allocator<T>&, const scalable_allocator<U>& ) {return true;}
    00169
    00170 template<typename T, typename U>
    00171 inline bool operator!=( const scalable_allocator<T>&, const scalable_allocator<U>& ) {return false;}
    00172
    00173 } // namespace tbb
    00174
    00175 #if _MSC_VER
    00176     #if __TBB_BUILD && !defined(__TBBMALLOC_NO_IMPLICIT_LINKAGE)
    00177         #define __TBBMALLOC_NO_IMPLICIT_LINKAGE 1
    00178     #endif
    00179
    00180     #if !__TBBMALLOC_NO_IMPLICIT_LINKAGE
    00181         #ifdef _DEBUG
    00182             #pragma comment(lib, "tbbmalloc_debug.lib")
    00183         #else
    00184             #pragma comment(lib, "tbbmalloc.lib")
    00185         #endif
    00186     #endif
    00187
    00188
    00189 #endif
    00190
    00191 #endif /* __cplusplus */
    00192
    00193 #if !defined(__cplusplus) && __ICC==1100
    00194     #pragma warning (pop)
    00195 #endif // ICC 11.0 warning 991 is back
    00196
    00197 #endif /* __TBB_scalable_allocator_H */

Copyright © 2005-2010 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.