Changeset ad83e4 in git


Ignore:
Timestamp:
Oct 25, 2008, 1:05:51 PM (15 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', '8d54773d6c9e2f1d2593a28bc68b7eeab54ed529')
Children:
3fe8ed4d13cc002b2f0fb89d6eeacd9ee3f7a568
Parents:
b0e3efca092d580bdd55fac90beff461dacda552
Message:
*hannes: new-nothrow


git-svn-id: file:///usr/local/Singular/svn/trunk@11159 2c84dea3-7e68-4137-9b89-c4e89433aadc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • factory/newdelete.cc

    rb0e3efc rad83e4  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: newdelete.cc,v 1.2 1997-06-19 12:22:03 schmidt Exp $ */
     2/* $Id: newdelete.cc,v 1.3 2008-10-25 11:04:06 Singular Exp $ */
    33
    44#include <config.h>
     
    1111#include "memman.h"
    1212#endif
     13
     14// The C++ standard has ratified a change to the new operator.
     15//
     16//  T *p = new T;
     17//
     18// Previously, if the call to new above failed, a null pointer would've been returned.
     19// Under the ISO C++ Standard, an exception of type std::bad_alloc is thrown.
     20// It is possible to suppress this behaviour in favour of the old style
     21// by using the nothrow version.
     22//
     23//  T *p = new (std::nothrow) T;
     24//
     25// So we have to overload this new also, just to be sure.
     26//
     27// A further interesting question is, if you don't have enough resources
     28// to allocate a request for memory,
     29// do you expect to have enough to be able to deal with it?
     30// Most operating systems will have slowed to be unusable
     31// long before the exception gets thrown.
    1332
    1433#ifdef USE_OLD_MEMMAN
     
    3251{
    3352    freeBlock( block, 0 );
     53}
     54
     55void * operator new(size_t size, const std::nothrow_t &) throw()
     56{
     57    return getBlock( size );
     58}
     59void * operator new[](size_t size, const std::nothrow_t &) throw()
     60{
     61    return getBlock( size );
    3462}
    3563
     
    5684}
    5785
     86void * operator new(size_t size, const std::nothrow_t &) throw()
     87{
     88    return mmAlloc( size );
     89}
     90void * operator new[](size_t size, const std::nothrow_t &) throw()
     91{
     92    return mmAlloc( size );
     93}
     94
    5895#endif /* USE_OLD_MEMMAN */
  • kernel/mmalloc.cc

    rb0e3efc rad83e4  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: mmalloc.cc,v 1.5 2006-07-27 09:09:37 Singular Exp $ */
     4/* $Id: mmalloc.cc,v 1.6 2008-10-25 11:05:51 Singular Exp $ */
    55/*
    66* ABSTRACT: standard version of C++-memory management alloc func
     
    1111
    1212#include <omalloc.h>
     13#include <new>
    1314
    1415/* We define those, so that our values of
     
    1819  void* addr;
    1920  if (!size) size = 1;
     21  omTypeAlloc(void*, addr, size);
     22  return addr;
     23}
     24
     25// The C++ standard has ratified a change to the new operator.
     26//
     27//  T *p = new T;
     28//
     29// Previously, if the call to new above failed, a null pointer would've been returned.
     30// Under the ISO C++ Standard, an exception of type std::bad_alloc is thrown.
     31// It is possible to suppress this behaviour in favour of the old style
     32// by using the nothrow version.
     33//
     34//  T *p = new (std::nothrow) T;
     35//
     36// So we have to overload this new also, just to be sure.
     37//
     38// A further interesting question is, if you don't have enough resources
     39// to allocate a request for memory,
     40// do you expect to have enough to be able to deal with it?
     41// Most operating systems will have slowed to be unusable
     42// long before the exception gets thrown.
     43
     44void * operator new(size_t size, const std::nothrow_t &) throw()
     45{
     46  void* addr;
     47  if (size==(size_t)0) size = (size_t)1;
    2048  omTypeAlloc(void*, addr, size);
    2149  return addr;
     
    3058{
    3159  void* addr;
    32   if (! size) size = 1;
     60  if (size==(size_t)0) size = (size_t)1;
    3361  omTypeAlloc(void*, addr, size);
    3462  return addr;
    3563}
     64
     65void * operator new[](size_t size, const std::nothrow_t &) throw()
     66{
     67  void* addr;
     68  if (size==(size_t)0) size = (size_t)1;
     69  omTypeAlloc(void*, addr, size);
     70  return addr;
     71}
     72
    3673
    3774void operator delete[] ( void* block )
Note: See TracChangeset for help on using the changeset viewer.