[Bf-committers] On MEM_Allocator.h

bjornmose at gmx.net bjornmose at gmx.net
Tue Feb 7 15:37:34 CET 2006


i can't get MEM_CacheLimiterC-Api complied on mcvc6.
i boiled it down to 

typedef std::list<MEM_CacheLimiterHandleCClass*,
                  MEM_Allocator<MEM_CacheLimiterHandleCClass*> 
				  > list_t;
not working, since MEM_Allocator<> is not recognized as allocator.

proof:
typedef std::list<MEM_CacheLimiterHandleCClass*,
                 
std::allocator<MEM_Allocator<MEM_CacheLimiterHandleCClass*>  >
				  > list_t;
compiles. 

However there are loads of MEM_Allocator< ... > 's in the code.

Comparing MEM_Allocator.h


template<typename _Tp>
struct MEM_Allocator:
{
	typedef size_t    size_type;
	typedef ptrdiff_t difference_type;
	typedef _Tp*       pointer;
.........

to 


The internal implementation of the allocator is completely irrelevant to the
vector itself. It is simply relying on the standardized public interface
every allocator has to provide.

The public interface is described by the ISO C++ standard, section 20.4.1:

   template <class T> class allocator {
    public:
      typedef size_t    size_type;
      typedef ptrdiff_t difference_type;
      typedef T*        pointer;
      typedef const T*  const_pointer;
      typedef T&        reference;
      typedef const T&  const_reference;
      typedef T         value_type;
      template <class U> struct rebind { typedef allocator<U>
                                         other; };
...............

i found there
http://www.codeguru.com/Cpp/Cpp/cpp_mfc/stl/article.php/c4079

and another example there 
http://www.codeguru.com/forum/showthread.php?t=282338
.....

template <class T>
class MyAlloc {
public:
  // type definitions
  typedef T        value_type;
  typedef T*       pointer;
  typedef const T* const_pointer;
  typedef T&       reference;
  typedef const T& const_reference;
  typedef std::size_t    size_type;
  typedef std::ptrdiff_t difference_type;

  // rebind allocator to type U
  template <class U >
  struct rebind {
    typedef MyAlloc< U > other;
  };

....

i wonder if there is a "proper" way of implementing an allocator which is
not realized in the MEM_Allocator.h code yet .. may be that one would
compile with msvc6 too?
just a thought ..
Ole

-- 
10 GB Mailbox, 100 FreeSMS/Monat http://www.gmx.net/de/go/topmail
+++ GMX - die erste Adresse für Mail, Message, More +++


More information about the Bf-committers mailing list