Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #4797

Re: Customize operator new / delete

Path csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c++
Subject Re: Customize operator new / delete
Date Sun, 08 May 2011 15:05:34 +1200
Lines 36
Message-ID <92mfjuF82qU2@mid.individual.net> (permalink)
References <e557f572-1a34-4a96-aad9-ffd1241a71be@c41g2000yqm.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net A4TngjfhzEgmNSFivcee6QTYh3J2ULTu1d7nox8kRoXWHkXMJd
Cancel-Lock sha1:GZvYZ4KRxY9uLJSmnGPjFEsGBzo=
User-Agent Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4
In-Reply-To <e557f572-1a34-4a96-aad9-ffd1241a71be@c41g2000yqm.googlegroups.com>
Xref x330-a1.tempe.blueboxinc.net comp.lang.c++:4797

Show key headers only | View raw


On 05/ 8/11 02:11 PM, Nephi Immortal wrote:
> 	I decide to customize my own operator new and operator delete in the
> global scope.  They are independent outside class as long as they are
> not function members of any class.
> 	Please confirm if my code is valid as C++ standard states.  I had
> examined across website via google search.  I only find user-defined
> classes, but not for global scope.
>
> #include<stdio.h>
> #include<malloc.h>
>
> inline
> void *operator new( size_t size ) { return malloc( size ); }
>
> inline
> void *operator new[]( size_t size ) { return malloc( size ); }
>
> inline
> void operator delete( void *pUserData ) { free( pUserData ); }
>
> inline
> void operator delete[]( void *pUserData ) { free( pUserData ); }
>
> int main()
> {
> 	char *p = new char[ 100 ];
> 	delete [] p;
>
> 	return 0;
> }

The code is fine, but I'd drop the "inline".  The draft C++0x standard 
prohibits it.

-- 
Ian Collins

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Customize operator new / delete Nephi Immortal <immortalnephi@gmail.com> - 2011-05-07 19:11 -0700
  Re: Customize operator new / delete Ian Collins <ian-news@hotmail.com> - 2011-05-08 15:05 +1200
  Re: Customize operator new / delete James Kanze <james.kanze@gmail.com> - 2011-05-08 07:38 -0700
    Re: Customize operator new / delete "io_x" <a@b.c.invalid> - 2011-05-08 19:05 +0200
      Re: Customize operator new / delete Nephi Immortal <immortalnephi@gmail.com> - 2011-05-08 15:35 -0700
        Re: Customize operator new / delete Ian Collins <ian-news@hotmail.com> - 2011-05-09 10:45 +1200
      Re: Customize operator new / delete James Kanze <james.kanze@gmail.com> - 2011-05-10 13:25 -0700
        Re: Customize operator new / delete "io_x" <a@b.c.invalid> - 2011-05-11 09:31 +0200
          Re: Customize operator new / delete "io_x" <a@b.c.invalid> - 2011-05-11 09:56 +0200
            Re: Customize operator new / delete James Kanze <james.kanze@gmail.com> - 2011-05-15 06:14 -0700
              Re: Customize operator new / delete Joshua Maurice <joshuamaurice@gmail.com> - 2011-05-15 23:54 -0700
                Re: Customize operator new / delete Ian Collins <ian-news@hotmail.com> - 2011-05-16 19:43 +1200
                Re: Customize operator new / delete Nobody <nobody@nowhere.com> - 2011-05-16 12:53 +0100
              Re: Customize operator new / delete "io_x" <a@b.c.invalid> - 2011-05-18 17:32 +0200
                Re: Customize operator new / delete Pete Becker <pete@versatilecoding.com> - 2011-05-18 12:38 -0400
          Re: Customize operator new / delete James Kanze <james.kanze@gmail.com> - 2011-05-15 06:12 -0700
  Re: Customize operator new / delete "io_x" <a@b.c.invalid> - 2011-05-08 18:44 +0200
    Re: Customize operator new / delete Nephi Immortal <immortalnephi@gmail.com> - 2011-05-08 15:43 -0700
      Re: Customize operator new / delete "io_x" <a@b.c.invalid> - 2011-05-09 08:47 +0200
        Re: Customize operator new / delete Leigh Johnston <leigh@i42.co.uk> - 2011-05-09 12:58 +0100
          Re: Customize operator new / delete "io_x" <a@b.c.invalid> - 2011-05-10 08:15 +0200
            Re: Customize operator new / delete Leigh Johnston <leigh@i42.co.uk> - 2011-05-10 12:39 +0100
        Re: Customize operator new / delete James Kanze <james.kanze@gmail.com> - 2011-05-10 13:29 -0700

csiph-web