Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

defalloc.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * Copyright (c) 1994
00004  * Hewlett-Packard Company
00005  *
00006  * Permission to use, copy, modify, distribute and sell this software
00007  * and its documentation for any purpose is hereby granted without fee,
00008  * provided that the above copyright notice appear in all copies and
00009  * that both that copyright notice and this permission notice appear
00010  * in supporting documentation.  Hewlett-Packard Company makes no
00011  * representations about the suitability of this software for any
00012  * purpose.  It is provided "as is" without express or implied warranty.
00013  *
00014  */
00015 
00016 // Inclusion of this file is DEPRECATED.  This is the original HP
00017 // default allocator.  It is provided only for backward compatibility.
00018 // This file WILL BE REMOVED in a future release.
00019 //
00020 // DO NOT USE THIS FILE unless you have an old container implementation
00021 // that requires an allocator with the HP-style interface.  
00022 //
00023 // Standard-conforming allocators have a very different interface.  The
00024 // standard default allocator is declared in the header <memory>.
00025 
00026 #ifndef _CPP_BACKWARD_DEFALLOC_H
00027 #define _CPP_BACKWARD_DEFALLOC_H 1
00028 
00029 #include "backward_warning.h"
00030 #include "new.h"
00031 #include <stddef.h>
00032 #include <stdlib.h>
00033 #include <limits.h> 
00034 #include "iostream.h" 
00035 #include "algobase.h"
00036 
00037 
00038 template <class _Tp>
00039 inline _Tp* allocate(ptrdiff_t __size, _Tp*) {
00040     set_new_handler(0);
00041     _Tp* __tmp = (_Tp*)(::operator new((size_t)(__size * sizeof(_Tp))));
00042     if (__tmp == 0) {
00043     cerr << "out of memory" << endl; 
00044     exit(1);
00045     }
00046     return __tmp;
00047 }
00048 
00049 
00050 template <class _Tp>
00051 inline void deallocate(_Tp* __buffer) {
00052     ::operator delete(__buffer);
00053 }
00054 
00055 template <class _Tp>
00056 class allocator {
00057 public:
00058     typedef _Tp value_type;
00059     typedef _Tp* pointer;
00060     typedef const _Tp* const_pointer;
00061     typedef _Tp& reference;
00062     typedef const _Tp& const_reference;
00063     typedef size_t size_type;
00064     typedef ptrdiff_t difference_type;
00065     pointer allocate(size_type __n) { 
00066     return ::allocate((difference_type)__n, (pointer)0);
00067     }
00068     void deallocate(pointer __p) { ::deallocate(__p); }
00069     pointer address(reference __x) { return (pointer)&__x; }
00070     const_pointer const_address(const_reference __x) { 
00071     return (const_pointer)&__x; 
00072     }
00073     size_type init_page_size() { 
00074     return max(size_type(1), size_type(4096/sizeof(_Tp))); 
00075     }
00076     size_type max_size() const { 
00077     return max(size_type(1), size_type(UINT_MAX/sizeof(_Tp))); 
00078     }
00079 };
00080 
00081 class allocator<void> {
00082 public:
00083     typedef void* pointer;
00084 };
00085 
00086 
00087 
00088 #endif /* _CPP_BACKWARD_DEFALLOC_H */

Generated at Tue May 1 16:28:37 2001 for libstdc++-v3 by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001