Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4680 | right-hear | 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. This is the original HP |
||
17 | // default allocator. It is provided only for backward compatibility. |
||
18 | // This file WILL BE REMOVED in a future release. |
||
19 | // |
||
20 | // DO NOT USE THIS FILE unless you have an old container implementation |
||
21 | // that requires an allocator with the HP-style interface. |
||
22 | // |
||
23 | // Standard-conforming allocators have a very different interface. The |
||
24 | // standard default allocator is declared in the header |
||
25 | |||
26 | #ifndef _CPP_BACKWARD_DEFALLOC_H |
||
27 | #define _CPP_BACKWARD_DEFALLOC_H 1 |
||
28 | |||
29 | #include "backward_warning.h" |
||
30 | #include "new.h" |
||
31 | #include |
||
32 | #include |
||
33 | #include |
||
34 | #include "iostream.h" |
||
35 | #include "algobase.h" |
||
36 | |||
37 | |||
38 | template |
||
39 | inline _Tp* allocate(ptrdiff_t __size, _Tp*) { |
||
40 | set_new_handler(0); |
||
41 | _Tp* __tmp = (_Tp*)(::operator new((size_t)(__size * sizeof(_Tp)))); |
||
42 | if (__tmp == 0) { |
||
43 | cerr << "out of memory" << endl; |
||
44 | exit(1); |
||
45 | } |
||
46 | return __tmp; |
||
47 | } |
||
48 | |||
49 | |||
50 | template |
||
51 | inline void deallocate(_Tp* __buffer) { |
||
52 | ::operator delete(__buffer); |
||
53 | } |
||
54 | |||
55 | template |
||
56 | class allocator { |
||
57 | public: |
||
58 | typedef _Tp value_type; |
||
59 | typedef _Tp* pointer; |
||
60 | typedef const _Tp* const_pointer; |
||
61 | typedef _Tp& reference; |
||
62 | typedef const _Tp& const_reference; |
||
63 | typedef size_t size_type; |
||
64 | typedef ptrdiff_t difference_type; |
||
65 | pointer allocate(size_type __n) { |
||
66 | return ::allocate((difference_type)__n, (pointer)0); |
||
67 | } |
||
68 | void deallocate(pointer __p) { ::deallocate(__p); } |
||
69 | pointer address(reference __x) { return (pointer)&__x; } |
||
70 | const_pointer const_address(const_reference __x) { |
||
71 | return (const_pointer)&__x; |
||
72 | } |
||
73 | size_type init_page_size() { |
||
74 | return max(size_type(1), size_type(4096/sizeof(_Tp))); |
||
75 | } |
||
76 | size_type max_size() const { |
||
77 | return max(size_type(1), size_type(UINT_MAX/sizeof(_Tp))); |
||
78 | } |
||
79 | }; |
||
80 | |||
81 | class allocator |
||
82 | public: |
||
83 | typedef void* pointer; |
||
84 | }; |
||
85 | |||
86 | |||
87 | |||
88 | #endif /* _CPP_BACKWARD_DEFALLOC_H */><>><> |