1 #ifndef CARMA_UTIL_MALLOC_ALLOCATOR_H
2 #define CARMA_UTIL_MALLOC_ALLOCATOR_H
12 template <
typename T >
13 class MallocAllocator {
18 typedef const T * const_pointer;
20 typedef const T & const_reference;
21 typedef ::std::size_t size_type;
22 typedef ::std::ptrdiff_t difference_type;
25 template <
typename U >
27 typedef MallocAllocator< U > other;
31 pointer address( reference value )
const {
35 const_pointer address( const_reference value )
const {
42 MallocAllocator( ) throw( ) { }
44 MallocAllocator(
const MallocAllocator & rhs )
throw( ) { }
46 template <
typename U >
47 MallocAllocator(
const MallocAllocator< U > & rhs )
throw( ) { }
49 ~MallocAllocator( ) throw( ) { }
52 size_type max_size ( )
const throw( ) {
53 return (::std::numeric_limits< ::std::size_t >::max( ) /
sizeof( T ));
57 pointer allocate( size_type num,
58 const void * dummy = 0 ) {
59 return static_cast< pointer
>( ::malloc( num *
sizeof( T ) ) );
63 void construct( pointer p,
66 new (
static_cast< void *
>( p )) T( value );
70 void destroy( pointer p ) {
76 void deallocate( pointer p,
79 ::free( static_cast< void * >( p ) );
86 template <
typename T1,
typename T2 >
88 operator==(
const MallocAllocator< T1 > & lhs,
const MallocAllocator< T2 > & rhs )
throw( ) {
93 template <
typename T1,
typename T2 >
95 operator!=(
const MallocAllocator< T1 > & lhs,
const MallocAllocator< T2 > & rhs )
throw( ) {