Boost logo

Boost Users :

From: David Baird (dhbaird_at_[hidden])
Date: 2007-10-31 20:31:20


Hi,

I was looking through the Pool code and noticed that it presents
inconsistent pointer types to the user ("void *" versus "char *").

For example, if the user wants to implement his/her own user
allocator, they have to write it like, e.g. (using "char *" as the
pointer type):

    struct default_user_allocator_new_delete
    {
      typedef std::size_t size_type;
      typedef std::ptrdiff_t difference_type;

      static char * malloc(const size_type bytes)
      { return new (std::nothrow) char[bytes]; }
      static void free(char * const block)
      { delete [] block; }
    };

However, other classes return "void *" as their pointer types, e.g.
singleton_pool:

    template <typename Tag, unsigned RequestedSize,
        typename UserAllocator,
        typename Mutex,
        unsigned NextSize>
    struct singleton_pool
    {
        static void * malloc()
        {
          pool_type & p = singleton::instance();
          details::pool::guard<Mutex> g(p);
          return p.p.malloc();
        }
    }

Is it really important that the types be different? I just think it
might be more elegant to use "void *" in more places - it would make
more things the same and be similar to e.g. "std::malloc/free".

-David


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net