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 7945179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:47:03+00:00 2026-06-04T00:47:03+00:00

I have encountered the following code: class a { public: void * operator new(size_t

  • 0

I have encountered the following code:

    class a {
    public:

        void *  operator new(size_t l, int nb);
        double  values;
    };
void *a::operator new (size_t l,int n)
{
    return new char[l+ (n>1 ? n - 1 : 0)*sizeof(double)];
}

From what I get it is then used to have an array like structure that start at “values”:

double* Val = &(p->a->values) + fColumnNumber;

My question is :
is there a memory leak? I am very new to overloading new operator, but I’m pretty sure that the memory allocated is not deallocated properly. Also does that mean I can never create a “a” class on the stack?

thanks

  • 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-04T00:47:04+00:00Added an answer on June 4, 2026 at 12:47 am

    I believe it technically produces UB as it is, though it’s a form of UB that will probably never cause a visible side effect (it’s using new [], but I believe that’ll get matched up with delete — but for char, this usually won’t cause a visible problem).

    IMO, it’s almost worse that it’s using a new expression to allocate what should really be raw bytes instead of objects. If I were doing it, I’d write it like:

    void *a::operator new (size_t l,int n)
    {
        return ::operator new(l+ (n>1 ? n - 1 : 0)*sizeof(double));
    }
    

    You’d match that up with:

    void a::operator delete(void *block)
    {
        ::operator delete(block);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just encountered this following code: public class TestFinally { public static void
I'm reading through the excellent Ruby on Rails Tutorial and have encountered the following
I have the following problem that other people must have encountered. I am working
We've encountered the following situation in our database. We have table 'A' and table
I'm learning C# and I encountered the following problem. I have two classes: base
I have got the following problem. I encountered an error regarding the default parameters.
Here is the test code template <class T> void f() { T t; t.f<T>(0);
Let's say I have the following code: // templateClass.h #ifndef TEMPLATE_CLASS_H #define TEMPLATE_CLASS_H template
I currently have a helper class to perform rudimentary AsyncTasks such as the following.
I encountered a class during my work that looks like this: public class MyObject

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.