Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #4797
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Customize operator new / delete |
| Date | 2011-05-08 15:05 +1200 |
| Message-ID | <92mfjuF82qU2@mid.individual.net> (permalink) |
| References | <e557f572-1a34-4a96-aad9-ffd1241a71be@c41g2000yqm.googlegroups.com> |
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
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