Jump to content
  • Advertisement
Sign in to follow this  
Desperado

Which forms of new and delete exist there?

This topic is 3819 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!