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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:22:37+00:00 2026-05-24T02:22:37+00:00

In my project, I have an abstract base class Base. I would like to

  • 0

In my project, I have an abstract base class “Base”. I would like to track all of the dynamic allocations/deallocations of objects that derive from “Base”. To this end, I’ve overridden the new/delete operators in “Base”.

After successfully allocating memory in the overridden new operator, I’d like to notify the object I’m using for tracking memory that an allocation has occurred, with the most derived type of the allocation and it’s size. The size isn’t a problem (as it’s passed directly in to the new operator for “Base”), but getting at the most derived type is an issue.

I’m leaning towards thinking this isn’t possible in the way I’m trying to do it. Since the more derived parts of the object haven’t been constructed yet, there’s no way to know what they are. However, the “Base” class’ overloaded new operator knows something about the final product- the size- so is it possible to know anything else about it?

For context:

void* Base::operator new( size_t size )
{
    void* storage = malloc( size );

    if ( storage == NULL )
        throw std::bad_alloc();

    // Notify MemoryTracker an allocation has occurred
    // MemoryTracker::Instance().Allocate( type, size );

    return storage;
}
  • 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-05-24T02:22:38+00:00Added an answer on May 24, 2026 at 2:22 am

    You’re right, it’s not possible this way, as new operator just allocates memory, nothing more. The right place to do such thing is constructor, not allocator, where you should be able to use RTTI to determine type of built object (and thus it can be done in Base constructor, not in every child class constructor).

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

Sidebar

Related Questions

In one C# project have a base class like this: public abstract class AbstractVersionedBase
In a proof-of-concept project I'm working on, I have a generic abstract class that
I am extending an existing C++ project. I have a base class that derives
I have a TypeConverter on the base class in my project. [TypeConverter(typeof(CodeTypeConverter))] abstract class
In my project I have a class that is inherited by many other classes.
I've written an abstract base class for unit tests that sets up just enough
I have an asp.net usercontrol (ascx) that inherits from an abstract class (that inherits
I have project that I'm working on that is going to require a webserver.
In my DSL project I have a shape with a number of decorators that
In a recent project I have nearly completed we used an architecture that as

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.