Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7763539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:41:05+00:00 2026-06-01T14:41:05+00:00

I am having hard time digesting this syntax: void* operator new[](std::size_t, const std::nothrow_t&) throw();

  • 0

I am having hard time digesting this syntax:

void* operator new[](std::size_t, const std::nothrow_t&) throw();

while this is still understood:

void* operator new (std::size_t size, const std::nothrow_t& nothrow_constant) throw();

Question:

  1. I thought new and subscript [] are different operators. how can we combine two operators to overload in one definition?

  2. Also the nowthrow. The following call doesnt make sense to me ( with respect to the signature of the function ).

     int * p2 = new (nothrow) int;
    

If anyone can give reference to related topics from bjarne stroustrup’s book that would be great, not a hard requirement though.

UPDATE: Please try to answer both questions 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:41:06+00:00Added an answer on June 1, 2026 at 2:41 pm

    The first two are the signatures of the global new operators. For what (little) it’s worth, operator new is used to allocate space for a new expression like x = new T;, while operator new[] is used to allocate space for a new expression like x = new T[count];. The “little” that it’s worth is for a fairly simple reason: you should never use new T[count], so how it works is almost purely a historical curiosity.

    You can overload ::operator new and/or ::operator new[] to provide your own heap allocation if you want to. There’s no difference between the two as far as basic requirements go — they both just allocate and return a pointer to the amount of memory requested.

    As far as nothrow goes, the size that gets passed to operator new is always computed by the compiler based on the size of the object and in the case of an array new the count you give. Therefore, the parameter you specify in the new expression turns into the second parameter that’s passed to operator new.

    To emphasize a point I may not have made quite clearly enough above: operator new (and operator new[]) are used by, but separate from new expressions (what you have in your code when you say something like x = new T;). operator new and operator new[] are pretty much like malloc — they just allocate “raw” memory. A new expression1 uses one of those to allocate raw memory, then invokes the constructor to allocate an object (or more than one, in the case of new T[count];) in that memory. The two are obviously related, but equally obviously not really the same.

    One other minor point: it’s also possible to have an operator new (or operator new[] as a class member. This allows you to allocate memory differently for that class than for others that use the global heap. This tends to be most common with small objects that you expect to allocate in large numbers. For these, the global heap often has quite a lot of overhead that you’d prefer to avoid.

    Finally, when/if you want to allocate raw memory, you can also invoke operator new directly, as in void *a = ::operator new(1234);. About the only place this is common is if you decide to implement some sort of collection class on your own (e.g., if you want a circular buffer).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was reading this: http://johnsantic.com/comp/state.html and having hard time comprehending this part: void (*const
I'm having hard time with this simple ajax call function sendreq() { $.ajax({ dataType:
Having a hard time figuring out the best way to do this... I have
I'm having hard time getting my head wrapped around this one - and it
im having hard time with this one, i want to create folder with write
I'm having hard time with this project, I'm building a boat configurator which is
I'm having hard time getting this snippet to work. I have made a minimal
I'm having hard time wrapping my head around this. I have an array called
I'm having hard time to get the right solution for this, so I need
I am new to Scala and I am having hard-time with defining, or more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.