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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:40:45+00:00 2026-06-14T09:40:45+00:00

I am trying to write a small memory leak detection tool. My idea is

  • 0

I am trying to write a small memory leak detection tool.

My idea is to track the dynamic memory allocation life with in my application
to determine any invalid access of memory or un deleted memory which might cause my application to core over a time of use.

I want to write a simple interface to override new and delete.

And in my overridden new i wanted to print function line address etc. And then call the standard new.

Have anyone already tried this? I am not sure whether i can call standard new from my class specific new operator.

  • 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-14T09:40:46+00:00Added an answer on June 14, 2026 at 9:40 am

    In this question i have proposed an ad-hoc solution to your problem: Immediate detection of heap corruption errors on Windows. How?

    In general, you can replace your new and delete with this code:

    DWORD PageSize = 0;
    
    inline void SetPageSize()
    {
        if ( !PageSize )
        {
            SYSTEM_INFO sysInfo;
            GetSystemInfo(&sysInfo);
            PageSize = sysInfo.dwPageSize;
        }
    }
    
    void* operator new (size_t nSize)
    {
        SetPageSize();
        size_t Extra = nSize % PageSize;
        nSize = nSize + ( PageSize - Extra );
        return Ptr = VirtualAlloc( 0, nSize, MEM_COMMIT, PAGE_READWRITE);
    }
    
    void operator delete (void* pPtr)
    {
        MEMORY_BASIC_INFORMATION mbi;
        VirtualQuery(pPtr, &mbi, sizeof(mbi));
        // leave pages in reserved state, but free the physical memory
        VirtualFree(pPtr, 0, MEM_DECOMMIT);
        DWORD OldProtect;
        // protect the address space, so noone can access those pages
        VirtualProtect(pPtr, mbi.RegionSize, PAGE_NOACCESS, &OldProtect);
    }
    

    to determine invalid access of memory. In the further discussion there you will find ideas for leaks detection and detection of other memory errors.

    If you want to call global new and delete, you can use :: global namespace prefix:

    return ::new(nSize);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a small Java application that will let me run
I'm trying to write a small application that needs to use the clipboard for
I am trying to write a small application using bouncycastle algorithm, from the BouncyCastleProvider.java
I'm trying to write a small application and have come across a compile time
I've been trying to write a small application which will work with mysql in
I am trying to write a small Cocoa application that helps me manage my
Here is a small function I'm trying to write to keep track of the
I am trying to write a small application, whose only purpose is to copy
I'm trying to write a small wsgi application which will put some objects to
Im trying to write a small application that makes isometric shapes. Ive been able

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.