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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:26:23+00:00 2026-06-16T03:26:23+00:00

In my pursuit of finding a particularly persistent memory leak in C++ code, I’ve

  • 0

In my pursuit of finding a particularly persistent memory leak in C++ code, I’ve resolved to writing all allocations to a log file in the following format:

<alloc|free> <address> <size> <UNIQUE-ID> <file> <line number>

This gives me, for example:

alloc 232108     60   405766 file1.cpp (3572)
free  232128     60   405766
alloc 232108     60   405767 file1.cpp (3572)
free  232128     60   405767
alloc 7a3620  12516   405768 file2.cpp (11435)
free  7a3640  12516   405768
alloc 2306c8    256   405769 file3.cpp (3646)
alloc 746160   6144   405770 file3.cpp (20462)
alloc 6f3528   2048   405771 file4.h (153)
alloc 6aca50    128   405772 file4.h (153)
alloc 632ec8    128   405773 file4.h (153)
alloc 732ff0    128   405774 file4.h (153)
free  746180   6144   405770
free  632ee8    128   405773
alloc 6a7610   2972   405778 this_alloc_has_no_counterpart.cpp (123)
free  6aca70    128   405772
free  733010    128   405774
free  6f3548   2048   405771
alloc 6a7610   2972   405775 file3.cpp (18043)
alloc 7a3620  12316   405776 file5.cpp (474)
alloc 631e00    256   405777 file3.cpp (18059)
free  7a3640  12316   405776
free  6a7630   2972   405775
free  631e20    256   405777
free  2306e8    256   405769

I’m trying to match every alloc to a free and leave just the allocs without a free counterpart, for example, allocation number 405778.

What I can come up with is the following shell script:

#!/bin/sh
grep "^alloc" test.txt | while read line
do
    alloc_nr=`echo $line | awk '{ print $4 }'`  # arg4 = allocation number
    echo "Processing $alloc_nr"
    sed -i "/ ${alloc_nr}/{//d}" test.txt
done

As you may have guessed, this is painstakingly slow (ie. 2 loops per second) on a 25MB file with about 144000 allocs, since I use sed in a horribly inefficient way.

It’d be very much appreciated if someone could give me a nudge in the right direction on how to achieve this without it taking three hours.

  • 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-16T03:26:24+00:00Added an answer on June 16, 2026 at 3:26 am

    Seems you want only the IDs and not the whole line:

    $ awk '{print $4}' file | sort | uniq -u
    405778
    

    awk '{print $4}' print only the ID column.

    sort sort the column.

    uniq -u display only the unique IDs.

    Edit:

    Pipe to grep -f - file to match the whole line, no need to loop:

    $ awk '{print $4}' file | sort | uniq -u | grep -f - file
    alloc 6a7610   2972   405778 this_alloc_has_no_counterpart.cpp (123)
    

    grep -f matches patterns from a file and - means use stdin.

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

Sidebar

Related Questions

We have a considerable code base with relatively high test coverage for pages/forms, all
In pursuit of finding the best way to have a date displayed on a
In the pursuit of elegant coding, I'd like to avoid having to catch an
According to link here , it is possible to get the source code under
I've been doing some reading on file formats and I'm very interested in them.
In my pursuit to learn javascript I am making the same slider, but with
I'm looking for a Matlab function which would decompose a signal using Matching Pursuit
Imagine C# code like this ISomeInterface someVar = creator.Create(typeof(SomeClass), typeof(ISomeInterface)); What should happen? Method
I am trying to load and save objects with this piece of code I
For my current project, I require the facility to be able to remove all

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.