- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Executives/DeductiveController/Configs/TI_DSP_BIOS/stl/defalloc.h

    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 DEFALLOC_H
    00027 #define DEFALLOC_H
    00028
    00029 #include <new.h>
    00030 #include <stddef.h>
    00031 #include <stdlib.h>
    00032 #include <limits.h>
    00033 #include <iostream.h>
    00034 #include <algobase.h>
    00035
    00036
    00037 template <class T>
    00038 inline T* allocate(ptrdiff_t size, T*) {
    00039     set_new_handler(0);
    00040     T* tmp = (T*)(::operator new((size_t)(size * sizeof(T))));
    00041     if (tmp == 0) {
    00042         cerr << "out of memory" << endl;
    00043         exit(1);
    00044     }
    00045     return tmp;
    00046 }
    00047
    00048
    00049 template <class T>
    00050 inline void deallocate(T* buffer) {
    00051     ::operator delete(buffer);
    00052 }
    00053
    00054 template <class T>
    00055 class allocator {
    00056 public:
    00057     typedef T value_type;
    00058     typedef T* pointer;
    00059     typedef const T* const_pointer;
    00060     typedef T& reference;
    00061     typedef const T& const_reference;
    00062     typedef size_t size_type;
    00063     typedef ptrdiff_t difference_type;
    00064     pointer allocate(size_type n) {
    00065         return ::allocate((difference_type)n, (pointer)0);
    00066     }
    00067     void deallocate(pointer p) { ::deallocate(p); }
    00068     pointer address(reference x) { return (pointer)&x; }
    00069     const_pointer const_address(const_reference x) {
    00070         return (const_pointer)&x;
    00071     }
    00072     size_type init_page_size() {
    00073         return max(size_type(1), size_type(4096/sizeof(T)));
    00074     }
    00075     size_type max_size() const {
    00076         return max(size_type(1), size_type(UINT_MAX/sizeof(T)));
    00077     }
    00078 };
    00079
    00080 class allocator<void> {
    00081 public:
    00082     typedef void* pointer;
    00083 };
    00084
    00085
    00086
    00087 #endif