defalloc.h revision 97403
117680Spst// Backward-compat support -*- C++ -*- 239300Sfenner 317680Spst// Copyright (C) 2001 Free Software Foundation, Inc. 417680Spst// 517680Spst// This file is part of the GNU ISO C++ Library. This library is free 617680Spst// software; you can redistribute it and/or modify it under the 717680Spst// terms of the GNU General Public License as published by the 817680Spst// Free Software Foundation; either version 2, or (at your option) 917680Spst// any later version. 1017680Spst 1117680Spst// This library is distributed in the hope that it will be useful, 1217680Spst// but WITHOUT ANY WARRANTY; without even the implied warranty of 1317680Spst// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1417680Spst// GNU General Public License for more details. 1517680Spst 1617680Spst// You should have received a copy of the GNU General Public License along 1717680Spst// with this library; see the file COPYING. If not, write to the Free 1817680Spst// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 1917680Spst// USA. 2017680Spst 2117680Spst// As a special exception, you may use this file as part of a free software 2217680Spst// library without restriction. Specifically, if other files instantiate 2317680Spst// templates or use macros or inline functions from this file, or you compile 2417680Spst// this file and link it with other files to produce an executable, this 2517680Spst// file does not by itself cause the resulting executable to be covered by 2617680Spst// the GNU General Public License. This exception does not however 2726183Sfenner// invalidate any other reasons why the executable file might be covered by 2839300Sfenner// the GNU General Public License. 2917680Spst 3017680Spst/* 3117680Spst * 3217680Spst * Copyright (c) 1994 3317680Spst * Hewlett-Packard Company 3417680Spst * 3517680Spst * Permission to use, copy, modify, distribute and sell this software 3617680Spst * and its documentation for any purpose is hereby granted without fee, 3717680Spst * provided that the above copyright notice appear in all copies and 3817680Spst * that both that copyright notice and this permission notice appear 3917680Spst * in supporting documentation. Hewlett-Packard Company makes no 4017680Spst * representations about the suitability of this software for any 4117680Spst * purpose. It is provided "as is" without express or implied warranty. 4221262Swollman * 4317680Spst */ 4417680Spst 4517680Spst// Inclusion of this file is DEPRECATED. This is the original HP 4617680Spst// default allocator. It is provided only for backward compatibility. 4717680Spst// This file WILL BE REMOVED in a future release. 4817680Spst// 4917680Spst// DO NOT USE THIS FILE unless you have an old container implementation 5039300Sfenner// that requires an allocator with the HP-style interface. 5117680Spst// 5239300Sfenner// Standard-conforming allocators have a very different interface. The 5317680Spst// standard default allocator is declared in the header <memory>. 5417680Spst 5517680Spst#ifndef _CPP_BACKWARD_DEFALLOC_H 5617680Spst#define _CPP_BACKWARD_DEFALLOC_H 1 5717680Spst 5817680Spst#include "backward_warning.h" 5917680Spst#include "new.h" 6017680Spst#include <stddef.h> 6117680Spst#include <stdlib.h> 6217680Spst#include <limits.h> 6317680Spst#include "iostream.h" 6417680Spst#include "algobase.h" 6517680Spst 6617680Spst 6717680Spsttemplate <class _Tp> 6817680Spstinline _Tp* allocate(ptrdiff_t __size, _Tp*) { 6917680Spst set_new_handler(0); 7017680Spst _Tp* __tmp = (_Tp*)(::operator new((size_t)(__size * sizeof(_Tp)))); 7117680Spst if (__tmp == 0) { 7217680Spst cerr << "out of memory" << endl; 7317680Spst exit(1); 7417680Spst } 7517680Spst return __tmp; 7626183Sfenner} 7717680Spst 7817680Spst 7917680Spsttemplate <class _Tp> 8017680Spstinline void deallocate(_Tp* __buffer) { 8117680Spst ::operator delete(__buffer); 8217680Spst} 8317680Spst 8417680Spsttemplate <class _Tp> 8517680Spstclass allocator { 8617680Spstpublic: 8717680Spst typedef _Tp value_type; 8817680Spst typedef _Tp* pointer; 8917680Spst typedef const _Tp* const_pointer; 9017680Spst typedef _Tp& reference; 9117680Spst typedef const _Tp& const_reference; 9217680Spst typedef size_t size_type; 9317680Spst typedef ptrdiff_t difference_type; 9417680Spst pointer allocate(size_type __n) { 9517680Spst return ::allocate((difference_type)__n, (pointer)0); 9617680Spst } 9717680Spst void deallocate(pointer __p) { ::deallocate(__p); } 9817680Spst pointer address(reference __x) { return (pointer)&__x; } 9917680Spst const_pointer const_address(const_reference __x) { 10017680Spst return (const_pointer)&__x; 10117680Spst } 10217680Spst size_type init_page_size() { 10317680Spst return max(size_type(1), size_type(4096/sizeof(_Tp))); 10417680Spst } 10517680Spst size_type max_size() const { 10617680Spst return max(size_type(1), size_type(UINT_MAX/sizeof(_Tp))); 10717680Spst } 10817680Spst}; 10917680Spst 11017680Spstclass allocator<void> { 11117680Spstpublic: 11217680Spst typedef void* pointer; 11317680Spst}; 11417680Spst 11517680Spst 11617680Spst 11717680Spst#endif /* _CPP_BACKWARD_DEFALLOC_H */ 11817680Spst