00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
#ifndef _MALLOC_ALLOCATOR_H
00031
#define _MALLOC_ALLOCATOR_H 1
00032
00033
#include <new>
00034
00035
namespace __gnu_cxx
00036 {
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
template<
typename _Tp>
00047 class malloc_allocator
00048 {
00049
public:
00050
typedef size_t size_type;
00051
typedef ptrdiff_t difference_type;
00052
typedef _Tp* pointer;
00053
typedef const _Tp* const_pointer;
00054
typedef _Tp& reference;
00055
typedef const _Tp& const_reference;
00056
typedef _Tp value_type;
00057
00058
template<
typename _Tp1>
00059
struct rebind
00060 {
typedef malloc_allocator<_Tp1> other; };
00061
00062
malloc_allocator()
throw() { }
00063
00064
malloc_allocator(
const malloc_allocator&)
throw() { }
00065
00066
template<
typename _Tp1>
00067
malloc_allocator(
const malloc_allocator<_Tp1>&)
throw() { }
00068
00069 ~
malloc_allocator()
throw() { }
00070
00071 pointer
00072 address(reference __x)
const {
return &__x; }
00073
00074 const_pointer
00075 address(const_reference __x)
const {
return &__x; }
00076
00077
00078
00079 pointer
00080 allocate(size_type __n,
const void* = 0)
00081 {
00082 pointer __ret = static_cast<_Tp*>(malloc(__n *
sizeof(_Tp)));
00083
if (!__ret)
00084
throw std::bad_alloc();
00085
return __ret;
00086 }
00087
00088
00089
void
00090 deallocate(pointer __p, size_type)
00091 { free(static_cast<void*>(__p)); }
00092
00093 size_type
00094 max_size()
const throw()
00095 {
return size_t(-1) /
sizeof(_Tp); }
00096
00097
00098
00099
void
00100 construct(pointer __p,
const _Tp& __val)
00101 { ::new(__p) value_type(__val); }
00102
00103
void
00104 destroy(pointer __p) { __p->~_Tp(); }
00105 };
00106
00107
template<
typename _Tp>
00108
inline bool
00109 operator==(
const malloc_allocator<_Tp>&,
const malloc_allocator<_Tp>&)
00110 {
return true; }
00111
00112
template<
typename _Tp>
00113
inline bool
00114 operator!=(
const malloc_allocator<_Tp>&,
const malloc_allocator<_Tp>&)
00115 {
return false; }
00116 }
00117
00118
#endif