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

The Archive Base Latest Questions

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

I am working on the memory allocator/snapshotting component of a runtime data flow/model analyzer

  • 0

I am working on the memory allocator/snapshotting component of a runtime data flow/model analyzer module. A part of our requirements is have the data structures of the test program allocated in a custom memory region that is under our control. In order to avoid, changing the test program we figured we have to define our own malloc/frees and the actual snapshotting/runtime checker module would use the system malloc whose pointer we would have got through the LD_PRELOADED mechanism( thanks Stackoverflow ). However, the real problem is with operator new. We could go the same route as before but new might internally use malloc( yet to look at kernel/libstdc++ code to verify this though ) and so we might end up actually using our malloc for both the test program as well as for the runtime checker module.
One solution I could come up with was overloading operator new somehow finding the caller context. ( I usually have a semantic like create a C++ object < set a recursive flag in constructor> clear it in the destructor ), allocate memory using either our malloc our glibc malloc based on the context, then use placement syntax of new to ensure the constructor gets called.
I would really like some pointers on when is the C++ constructor actually invoked, i am 90% sure it is part of new because returns a pointer to that object, but the only implementation of new which i have seen( VSCRT ) uses malloc and does not have an apparent constructor invocation.
My question is:
1) I would like some feedback on my general idea?
2) When is the constructor exactly invoked?

Best,
Subramanian

  • 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:43:35+00:00Added an answer on June 1, 2026 at 2:43 pm

    Whan you overload the new operator, you only overload the memory allocation process, not the call to the constructor (that, I believe, is done by the compiler by emitting the necessary code to call the constructor on the space returned by new) — similar with `delete: only free the allocated space (after the destructor has been called already).

    So, the quick answer to your question is that you can overload operator new/delete to use your specific memory allocation scheme (e.g. via malloc/free) and the object creation will be taken care of by the generated exectable code.

    Note: you do not need any extra parameter for the constructor (you can’t even provide one for the destructor) — by the time the constructor is called the memory is successfully allocated (otherwise the constructor would not have been called to begin with)

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

Sidebar

Related Questions

I'm working on a custom mark-release style memory allocator for the D programming language
once I tried TBB memory allocator in the project I was working on (MMORPG
I'm currently working on a device with very little memory (4MB) and I have
I'm working on a memory tracking library where we use mprotect to remove access
I'm working on a memory pool implementation and I'm a little confused about pointers
I'm working on a Memory Scanner, but the scan is so slow.. can anybody
I would like to display some memory statistics (working set, GCs etc.) on a
How do I calculate the private working set of memory using C#? I'm interested
I am working with a shared memory application, and to delete the segments I
I'm working on an embedded device that does not support unaligned memory accesses. For

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.