473,902 Members | 3,399 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

purge like utility in c

hi .. can we design a program in c which will point out the possible
memory leaks in any given c file and fix them.... i am trying to come
with something like this but do not know where to start...

any help on where to begin would be highly appriciated
kind regards
rahul

Oct 10 '06
118 4458
jacob navia said:

<snip>
>
Maybe. Better do not use [garbage collection].
Excellent advice.
Use malloc/free and do everything manually with all the associated bugs.
I'm happy to use malloc/free, but I see no need to include the bugs.
I was recommending the GC for other people that like caring about their
programs, their algorithms, their deadlines, instead of chasing
malloc/free bugs!!!
The claim "Jacob Navia can't use malloc/free without riddling his programs
with bugs" is a reasonable one, and if that's what you're claiming, I take
your word for it. But the claim "nobody else can either" is ridiculous.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 10 '06 #41
jacob navia said:

<snip>
There is a whole INDUSTRY of software for chasing
malloc/free bugs. Huge software systems like valgrind,
purify, etc etc are built JUST TO CHASE THOSE BUGS.
Yeah. That's one reason they're so easy to find and fix. Duh.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 10 '06 #42
jacob navia wrote:
Besides, all other languages do not provide with the efficiency
of C. Coupled with a good GC, the need for destructors, and
all the associated machinery disappears. You obtain a simpler,
easier to use language, without the problems of other "OO"
stuff.
does your garbage collection close files for me too?

Oct 10 '06 #43
jacob navia <ja***@jacob.re mcomp.frwrites:
Richard Heathfield wrote:
>jacob navia said:
>>>Richard Heathfield wrote:

But of course there is always valgrind...

Interestin g. You recommend valgrind,
No, I just mentioned it, that's all. I don't recommend it (and
neither do I recommend against it). How can I? I've never needed to
use it. But I am told by its users that it's very helpful to them.
>>>but you are against a Garbage Collector.
My understanding of valgrind is that you can use it without
modifying your C source code, so the program remains uncorrupted by
the tool. And, having used it to identify and remove any leaks from
your program, the program remains portable, and can still work
independentl y of valgrind, so portability is not affected.
Is my understanding of valgrind incorrect? Or, if I've got it about
right, can you claim the same characteristics for your garbage
collector? That is, can it work without the C source having to call
any of its routines, and will the program still work correctly
without leaking memory even when that program is moved to a platform
where the garbage collector is unavailable? If so, then I remove my
objections. Otherwise, I don't.

You do:
#define malloc(a) GC_malloc(a)
#define free(a)

And that is it.
No, that is not it.

In addition to your two #defines, you need to tell the linker where to
find the GC_malloc() function. And if you don't add a #include for
whatever header contains the declaration of GC_malloc, you'll invoke
undefined behavior every time you call it, just like calling malloc()
without a "#include stdlib.h>". This will be a real problem on
systems with 32-bit int and 64 bit pointers, for example.

I wonder what else you've left out.
Most programs will work like this, unless (of course) they write
pointers to a file, or put their pointers in e-mail messages, or
whatever.

We have discussed this several times.
And every time it comes up, you advocate GC, but somebody else has to
mention the limitations. Garbage collection may be the greatest thing
since sliced bread, but nobody should try to use it without
understanding the caveats.

Garbage collection can work only if all pointer values in the program
are visible to the garbage collector at all times. That's probably
already the case for most programs, but ignoring the issue is
dangerous.
By the way, the limitations of valgrind are FAR more long. See my reply
to "Flash Gordon"...
I looked over it very briefly. It only works on a limited set of
platforms; that's ok if your code is portable and you have access to
such a system. (Yes, that's a real limitation that you should be
aware of.) Most of the other limitations seemed to apply only to code
that uses system-specific features. And all this was in response to a
brief *mention* of valgrind by Richard Heathfield. (I've never used
it myself, so I can't really comment further.)

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Oct 10 '06 #44
Fellas! Come On!

Senator Ted Stevens has caught on! We're clogging up the Internet
pipes with all these long discussions!

I suggest we get the feds off our backs by coming up with a set of
well-known abbreviations, denoted by letters, thereby shortening these
interminable postings, something like:

A: I am wonderful, all-knowing, and generally infallible.
B: Use a garbage collector.
C: It's not C.
D: It's not K&R C.
E: you misdeclared main()
F: Use my wonderful C compiler, only slightly buggy.
G: Oh if only C had feature X of language Y!
H: Please fix my program below, it has an obscure problem.
I: Oh yes you can.
J: Oh no you can't.
K: I blow my nose in your general direction.

.... rest to be assigned as needed.

thereby all the stuff clogging the pipes can be reduced to a short
series of capital letters.
For even more brevity, we can just assume each posting ends with "K"
unless otherwise noted.

Oct 10 '06 #45
ra************* ******@gmail.co m wrote:
hi .. can we design a program in c which will point out the possible
memory leaks in any given c file and fix them.... i am trying to come
with something like this but do not know where to start...

any help on where to begin would be highly appriciated
kind regards
rahul

For each call to malloc you should have a call to free to let go of
that mem segment. A simplistic way of tracing any potential leaks is
discribed by Franek in his book: Memory as a Programming Concept in C
and C+, using the preprocessor:

#define malloc(size) debug_malloc(__ FILE__,__LINE__ ,size)
#define free(ptr) debug_free(__FI LE__,__LINE__,p tr)

protoypes:

void debug_malloc(co nst char *src,int line, size_t size)
void debug_free(cons t cahr *src,int line, void* ptr)

then simply link it to the definitions of these in your program and you
can have a handy reference of what was allocated and what was freed.
Good book and will help you think how you could fully implement your
question. I tried it out, but it can get a bit hairy as your code
becomes more complex...nice place to start though.

Oct 10 '06 #46
Richard Heathfield <in*****@invali d.invalidwrites :
jacob navia said:
<snip>
>>
Maybe. Better do not use [garbage collection].

Excellent advice.
>Use malloc/free and do everything manually with all the associated bugs.

I'm happy to use malloc/free, but I see no need to include the bugs.
>I was recommending the GC for other people that like caring about their
programs, their algorithms, their deadlines, instead of chasing
malloc/free bugs!!!

The claim "Jacob Navia can't use malloc/free without riddling his programs
with bugs" is a reasonable one, and if that's what you're claiming, I take
your word for it. But the claim "nobody else can either" is ridiculous.
Garbage collection in C may or may not be a good solution for some
problems in some circumstances. The fact that its major advocate in
this newsgroup chooses to insult anyone who points out any potential
flaws shouldn't prevent anyone from looking into it. Ignoring jacob
navia needn't imply ignoring GC.

Of course, if you choose not to use GC, that's ok too; I make no
recommendation one way or the other.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Oct 10 '06 #47
ra************* ******@gmail.co m wrote:
hi .. can we design a program in c which will point out the possible
memory leaks in any given c file and fix them.
http://en.wikipedia.org/wiki/Memory_debugger
Oct 10 '06 #48
Ancient_Hacker wrote:
well, any use of malloc() without a later free() is going to leak....
But I think it's ttheoretically impossible to figure out what mallocs()
never do a free() without executing all possible paths thru the code
with all possible inputs.
Halting Problem, proven undecidable.
Oct 10 '06 #49
In article <Lr************ *************** ***@bt.com>,
Richard Heathfield <in*****@invali d.invalidwrote:
>My understanding of valgrind is that you can use it without modifying your C
source code, so the program remains uncorrupted by the tool.
There are garbage collectors for C with that property. You just link
with a different version of malloc() and free(), where typically the
latter is a no-op.
>And, having
used it to identify and remove any leaks from your program, the program
remains portable, and can still work independently of valgrind, so
portability is not affected.
Is a program that never calls free() portable? It just sees different
implementation limits from one which does.
>will the program still work correctly without leaking memory even when that
program is moved to a platform where the garbage collector is unavailable?
A conforming C implementation is not required not to leak memory, is it?

Seriously, a conservative garbage collector is a reasonable approach
if your program fits certain common constraints and your portability
requirements match the collector in question. Much the same as deciding
to rely on a non-standard library, really.

-- Richard
Oct 10 '06 #50

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4433
by: Dan Caron | last post by:
I have to create a stored procedure to purge "x" # of records from a table. I have two tables (script below): Schedule ScheduleHistory I need to purge records out of ScheduleHistory. The problem is that the # of records that needs to be "kept" is dynamic, and stored in the Schedule table. So all records in ScheduleHistory should be purged, except for the most recent "x" number of records.
1
2279
by: Heather | last post by:
Is it possible to automatically purge records after a six month period in Microsoft Access 97?
5
2311
by: Diffident | last post by:
Hello All, I have written a webform which is by default derived from "Page" class. I have coded another utility class with few methods and an object of this class is instantiated from the webfom class. Methods inside the utility class set few global variables which act as mediums of persistence to hold data. Now my question is all works fine during my initial request and all the global variables are set correctly, but during later...
5
5409
by: Jeff | last post by:
We are using .Net and the wsdl Utility to generate proxies to consume web services built using the BEA toolset. The data architects on the BEA side create XML schemas with various entities in separate files for ease of maintainability. These schemas are all part of the same namespace. When defining a web service that access more than one of these entities, the wsdl file generated by BEA contains multiple schema elements with the same...
1
5969
by: huyuhui | last post by:
The following is a question of LOAD utility. Question: How does the DB2 enforce table check constraints for data added to table with the LOAD utility? A. With the BUILD phase of LOAD B. With the SET INTEGRITY statement C. With the DELETE phase of the LOAD D. With the UPDATE CONSTRAINTS statement Answer is A
27
2168
by: Neil | last post by:
Anyone have a recommendation for a good inexpensive or free utility for developing table schemas.
3
2060
by: kababoom | last post by:
Hi All, I am new to PLSQL. I am posting this query. Wat i need : to purge and export oracle table data which is more than 1 month old onto a csv file Thks for any advice :)
1
1479
by: kenderkin17 | last post by:
I have an older Database of personel records that I need to completely purge, but keep all of the current macros data and relationships. Is there a command line or code that will simply remove all of the stored data in the input fields for the DB while maintaining the integrity of the previous commands and macros? I understand that you may need to know all of the previous macros and things of that nature. If there is a simple command that...
0
2040
by: hsheboul | last post by:
Thanks to Markus for pointing me to all the Apache stuff http://bytes.com/topic/html-css/answers/876342-automating-web-site-template My Web site is hosted on a shared Linux hosting, that runs the Apache 2.2 I got multiple static "utility" files: CSS, JavaScripts, Impages, etc. In order to maintain a coherent and consistent structure, I put all these kind of utility files in one directory hierarchy. However, this directory structure might...
0
9997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9845
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11279
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10981
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10499
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9675
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4725
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4307
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.