gcc/libstdc++-v3/include/backward/defalloc.h

89 lines
2.4 KiB
C
Raw Normal View History

/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
// Inclusion of this file is DEPRECATED. This is the original HP
// default allocator. It is provided only for backward compatibility.
// This file WILL BE REMOVED in a future release.
//
// DO NOT USE THIS FILE unless you have an old container implementation
// that requires an allocator with the HP-style interface.
//
// Standard-conforming allocators have a very different interface. The
// standard default allocator is declared in the header <memory>.
#ifndef _CPP_BACKWARD_DEFALLOC_H
#define _CPP_BACKWARD_DEFALLOC_H 1
Warn when using backward headers. 2001-04-05 Benjamin Kosnik <bkoz@redhat.com> Warn when using backward headers. * include/backward/algo.h: Include warning file. * include/backward/vector.h: Same. * include/backward/tree.h: Same. * include/backward/tempbuf.h: Same. * include/backward/strstream: Same. * include/backward/streambuf.h: Same. * include/backward/stream.h: Same. * include/backward/stack.h: Same. * include/backward/slist.h: Same. * include/backward/set.h: Same. * include/backward/rope.h: * include/backward/queue.h: Same. * include/backward/pair.h: Same. * include/backward/ostream.h: Same. * include/backward/new.h: Same. * include/backward/multiset.h: Same. * include/backward/multimap.h: Same. * include/backward/map.h: Same. * include/backward/list.h: Same. * include/backward/iterator.h: Same. * include/backward/istream.h: Same. * include/backward/iostream.h: * include/backward/iomanip.h: * include/backward/heap.h: Same. * include/backward/hashtable.h: * include/backward/hash_set.h: * include/backward/hash_map.h: * include/backward/function.h: * include/backward/fstream.h: * include/backward/deque.h: * include/backward/defalloc.h: Same. * include/backward/complex.h: Same. * include/backward/bvector.h: * include/backward/alloc.h: * include/backward/algobase.h: Same. * include/backward/backward_warning.h: New file. * src/Makefile.am (backward_headers): Add backward_warning.h * src/Makefile.in: Regenerate. 2001-04-05 Benjamin Kosnik <bkoz@redhat.com> * src/Makefile.am (myinstalldirs): Make sure backward directory is created. (myinstallheaders): Install backward headers in backward directory. * src/Makefile.in: Regenerate. From-SVN: r41139
2001-04-05 23:08:17 -07:00
#include "backward_warning.h"
#include "new.h"
#include <stddef.h>
#include <stdlib.h>
#include <limits.h>
#include "iostream.h"
#include "algobase.h"
template <class _Tp>
inline _Tp* allocate(ptrdiff_t __size, _Tp*) {
set_new_handler(0);
_Tp* __tmp = (_Tp*)(::operator new((size_t)(__size * sizeof(_Tp))));
if (__tmp == 0) {
cerr << "out of memory" << endl;
exit(1);
}
return __tmp;
}
template <class _Tp>
inline void deallocate(_Tp* __buffer) {
::operator delete(__buffer);
}
template <class _Tp>
class allocator {
public:
typedef _Tp value_type;
typedef _Tp* pointer;
typedef const _Tp* const_pointer;
typedef _Tp& reference;
typedef const _Tp& const_reference;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
pointer allocate(size_type __n) {
return ::allocate((difference_type)__n, (pointer)0);
}
void deallocate(pointer __p) { ::deallocate(__p); }
pointer address(reference __x) { return (pointer)&__x; }
const_pointer const_address(const_reference __x) {
return (const_pointer)&__x;
}
size_type init_page_size() {
return max(size_type(1), size_type(4096/sizeof(_Tp)));
}
size_type max_size() const {
return max(size_type(1), size_type(UINT_MAX/sizeof(_Tp)));
}
};
class allocator<void> {
public:
typedef void* pointer;
};
#endif /* _CPP_BACKWARD_DEFALLOC_H */