Topic: ISO-C++: allocator


Author: schuenem@informatik.tu-muenchen.de (Ulf Schuenemann)
Date: 1995/05/26
Raw View
Ad description of allocator:
----------------------------------------------------------
20.4.1.1[lib.allocator,members]

> template<class T,class U>
>  typename types<T>::pointer
>   allocate(size_t n, typename types<U>::const_pointer hint)
> Notes: Uses ::operator new(size_t)
> Returns: new T, if n == 1. Returns new T[n], if n > 1.

(1) What is the purpos of 'hint'? Is its only purpose to allow different
    template specialisations? Then allocate<T,U>(n) would be enough.
    NB: You already have to use explicit template form as T cannot be
    derived from the parametertypes.

    Similar for 20.4.3.1[lib.allocate]:
    > template<class T> T* allocate(ptrdiff_t n, T*);
    What is the T*-parameter good for? Why not using allocate<T>(n) ?

(2) How does this fit together: For n > 1 it returns new T[n],
    but it only uses ::operators new(). Maybe it's placement new-expression:
    'Returns new(::operator new(n*sizeof T)) T[n], if n > 1'
    NB ::operator new[]() must _not_ be used, as deallocate uses
    ::operator delete().

(3) What happens if n == 0?
    NB that 3.7.3.1[basic.stc.dynamic.allocation] explicitly allows n==0
    for 'allocation functions'.
    NB 20.4.3.1[lib.allocate] explicitly allows n>=0 for
    template<class T> T* allocate(ptrdiff_t n, T*);


Ulf Schuenemann

--------------------------------------------------------------------
Ulf Sch   nemann
Fakult   t f   r Informatik, Technische Universit   t M   nchen, Germany.
email: schuenem@informatik.tu-muenchen.de