home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / libg++-2.7.1-bin.lha / lib / g++-include / lngalloc.h < prev    next >
C/C++ Source or Header  |  1996-10-12  |  1KB  |  55 lines

  1. /*
  2.  *
  3.  * Copyright (c) 1994
  4.  * Hewlett-Packard Company
  5.  *
  6.  * Permission to use, copy, modify, distribute and sell this software
  7.  * and its documentation for any purpose is hereby granted without fee,
  8.  * provided that the above copyright notice appear in all copies and
  9.  * that both that copyright notice and this permission notice appear
  10.  * in supporting documentation.  Hewlett-Packard Company makes no
  11.  * representations about the suitability of this software for any
  12.  * purpose.  It is provided "as is" without express or implied warranty.
  13.  *
  14.  */
  15.  
  16. #ifndef LNGALLOC_H
  17. #define LNGALLOC_H
  18.  
  19. #include <limits.h>
  20. #include <algobase.h>
  21. #include <defalloc.h>
  22.  
  23. template <class T>
  24. class long_allocator {
  25. public:
  26.     typedef T value_type;
  27.     typedef T* pointer;
  28.     typedef const T* const_pointer;
  29.     typedef T& reference;
  30.     typedef const T& const_reference;
  31.     typedef unsigned long size_type;
  32.     typedef long difference_type;
  33.     pointer allocate(size_type n) { 
  34.     return ::allocate((difference_type)n, (pointer)0);
  35.     }
  36.     void deallocate(pointer p) { ::deallocate(p); }
  37.     pointer address(reference x) { return (pointer)&x; }
  38.     const_pointer const_address(const_reference x) { 
  39.     return (const_pointer)&x; 
  40.     }
  41.     size_type init_page_size() { 
  42.     return max(size_type(1), size_type(4096/sizeof(T))); 
  43.     }
  44.     size_type max_size() const { 
  45.     return max(size_type(1), size_type(ULONG_MAX/sizeof(T))); 
  46.     }
  47. };
  48.  
  49. class long_allocator<void> {
  50. public:
  51.     typedef void* pointer;
  52. };
  53.  
  54. #endif
  55.