Which forms of new and delete exist there?

Started by
2 comments, last by Desperado 15 years, 9 months ago
Hello folks, another question: Currently, I'm trying to rewrite operator new and delete for a class. The standard lists 8 function prototypes as defined in <new> in 17.4.3.4: * operator new(size_t) * operator new(size_t, const std::nothrow_t&) * operator new[](size_t) * operator new[](size_t, const std::nothrow_t&) * operator delete(void*) * operator delete(void*, const std::nothrow_t&) * operator delete[](void*) * operator delete[](void*, const std::nothrow_t&) However, this list doesn't include placement and 2 parameter style types. Is there a full list anywhere of all possible operator new/delete s? 2 more questions: - Are more than 2 parameters possible for any of this functions? - I can switch the parameter type of the memory are with the specific class type, right, meaning: operator delete[](void*) can be replaced by operator delete[](VyVeryOwnClass*) right? Thanks!
Advertisement
I have a funny feeling I know the answer to this, but is there a reason why you need > 2 parameters for the new/delete operators?

I've written my own memory manager and overloaded the operators as;

extern void *operator new(size_t numOfBytes,MemoryPool *Pool);
extern void operator delete(void *p,MemoryPool *Pool);

the MemoryPool parameter is a pointer to my class, which handles this; any additional parameters I need for memory management are stored within this class.

as I remember it (some time ago I wrote this) I had a tricky time with the delete operator determining "which" bit of memory needed to be removed, and identification but got around it by using the void *p pointer as a reference to whatever object was in the pool at the time.
http://www.fotofill.co.uk
17.4.3.4 doesn't list the function prototypes for the new and delete overloads in the <new> header; it lists which function prototypes the program may supply definitions for. The complete list of function prototypes for new and delete overloads in the <new> header is in section 18.4.
Quote:Original post by SiCrane
17.4.3.4 doesn't list the function prototypes for the new and delete overloads in the <new> header; it lists which function prototypes the program may supply definitions for. The complete list of function prototypes for new and delete overloads in the <new> header is in section 18.4.


My bad.

Then as follow up questions:

- Can I specify operator delete(void*, Param1*, Param2*)

if I wanted to (3 paremeters)? Will it still be compatible with 'delete'?

- On the base of which paragraphs are the default implementations from 18.4 composed?

Thanks!

This topic is closed to new replies.

Advertisement