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

  • SEARCH
  • Home
  • 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 8323161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:38:10+00:00 2026-06-08T23:38:10+00:00

We want to overload placement new operator just to verify that used memory size

  • 0

We want to overload placement new operator just to verify that used memory size is enough for the given class. We know this size. The construction is more or less in this way:

template <size_t MAXSIZE>
class PlacementNewTest {
public:
  void* operator new (size_t size, void* where)
  {
     if (size > MAXSIZE) {
        throw bad_alloc();
     }
     return where;
  }
};

Let say used in such simplified context:

char buffer[200];

class A : public PlacementNewTest<sizeof buffer> {
public:
   char a[100];  
};

class B : public A {
public:
   char b[200];  
};


int main() {
   A* a = new (buffer) A; // OK
   a->~A();
   B* b = new (buffer) B; // throwed bad_alloc
   b->~B();
}

During testing phase I have this PlacementNewTest<> class used, but in the release code I consider to remove it. Do you think, basing on your experience, how much this will cost our performance, not to remove this extra test class? Is this only cost of this verification if (size > MAXSIZE)?
In other words, what is performance penalty for such redefinition:

class PlacementNewNOP {
public:
  void* operator new (size_t size, void* where)
  {
     return where;
  }
};

Maybe it is not important in this question – but:
This is, and must be, C++03. We cannot upgrade to C++11. And boost is not an option too, just C++03.

  • 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-08T23:38:12+00:00Added an answer on June 8, 2026 at 11:38 pm

    There shouldn’t be any overhead apart from the comparison, unless you are using virtual methods, the binding is static.

    Of course there is the exception overhead, but since that is something that shouldn’t happen, you should be safe to ignore it.

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

Sidebar

Related Questions

I want to overload new operator in a template class. But something wrong happends.
I want to overload the >> operator in c++ so that my class of
I want to overload failUnlessEqual in unittest.TestCase so I created a new TestCase class:
I want to overload the operator , so that I can assign my fraction
I have a Card class and I want to overload the > operator to
I have a smart pointer class and I want to overload operator-> ; it's
I'm writing a collection class. I want to overload the square brackets operator ([])
I want to overload the operator + in a class which has a vector
I have a simple class for which I want to overload operator as below
I have a class that uses a struct, and I want to overload the

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.