"Fossies" - the Fresh Open Source Software Archive

Member "erltools/stl/defalloc.h" (25 Jul 1999, 2319 Bytes) of package /linux/misc/old/erltools-4.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "defalloc.h" see the Fossies "Dox" file reference documentation.

    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 //  Inclusion of this file is DEPRECATED.
   17 //  This is the original HP default allocator.
   18 //  DO NOT USE THIS FILE unless you have an old container implementation
   19 //  that requires an allocator with the HP-style interface.
   20 //  SGI STL uses a different allocator interface.
   21 //  SGI-style allocators are not parametrized with respect to
   22 //  the object type; they traffic in void * pointers.
   23 //  This file is not included by any other SGI STL header.
   24 //
   25 
   26 #ifndef DEFALLOC_H
   27 #define DEFALLOC_H
   28 
   29 #include <new.h>
   30 #include <stddef.h>
   31 #include <stdlib.h>
   32 #include <limits.h>
   33 #include <iostream.h>
   34 #include <algobase.h>
   35 
   36 
   37 template <class T>
   38 inline T* allocate(ptrdiff_t size, T*) {
   39     set_new_handler(0);
   40     T* tmp = (T*)(::operator new((size_t)(size * sizeof(T))));
   41     if (tmp == 0) {
   42     cerr << "out of memory" << endl; 
   43     exit(1);
   44     }
   45     return tmp;
   46 }
   47 
   48 
   49 template <class T>
   50 inline void deallocate(T* buffer) {
   51     ::operator delete(buffer);
   52 }
   53 
   54 template <class T>
   55 class allocator {
   56 public:
   57     typedef T value_type;
   58     typedef T* pointer;
   59     typedef const T* const_pointer;
   60     typedef T& reference;
   61     typedef const T& const_reference;
   62     typedef size_t size_type;
   63     typedef ptrdiff_t difference_type;
   64     pointer allocate(size_type n) { 
   65     return ::allocate((difference_type)n, (pointer)0);
   66     }
   67     void deallocate(pointer p) { ::deallocate(p); }
   68     pointer address(reference x) { return (pointer)&x; }
   69     const_pointer const_address(const_reference x) { 
   70     return (const_pointer)&x; 
   71     }
   72     size_type init_page_size() { 
   73     return max(size_type(1), size_type(4096/sizeof(T))); 
   74     }
   75     size_type max_size() const { 
   76     return max(size_type(1), size_type(UINT_MAX/sizeof(T))); 
   77     }
   78 };
   79 
   80 class allocator<void> {
   81 public:
   82     typedef void* pointer;
   83 };
   84 
   85 
   86 
   87 #endif