Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Smart Pointers: Is there something similar to smart pointers in C?

Reply
Thread Tools

Smart Pointers: Is there something similar to smart pointers in C?

 
 
jacob navia
Guest
Posts: n/a
 
      09-12-2006
Ancient_Hacker wrote:
> MotoK wrote:
>
>>Hi Experts,
>>I've just joined this group and want to know something:
>>Is there something similar to smart pointers in C or something to
>>prevent memory leakages in C programs.
>>
>>Regards
>>MotoK

>
>
> IMHO you can't do that in C. C gives you complete freedom to make
> copies of pointers, do pointer arithmetic, pass the address of a
> pointer, call arbitrary functions written in bizarre languages--- all
> things that will screw up smart pointers and garbage collection to a
> fare-thee-well, or at least a seg fault.
>
> What I do is write a logging malloc() and free() so at the end of the
> program it can print out "37122 unfreed blocks using 293455128 bytes".
> And then a list of file names and lines where those blocks were
> malloc'ed.
>


You are wrong what GC is concerned.
Normal C programs do not need a lot of care to use the GC,
and unless you explicitely hide the pointers from the GC
garbage collection will work perfectly with C.
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      09-12-2006
jacob navia <(E-Mail Removed)> writes:
[...]
> You are wrong what GC is concerned.
> Normal C programs do not need a lot of care to use the GC,
> and unless you explicitely


.... or implicitly ...

> hide the pointers from the GC
> garbage collection will work perfectly with C.


--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <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.
 
Reply With Quote
 
 
 
 
Mark McIntyre
Guest
Posts: n/a
 
      09-12-2006
On Tue, 12 Sep 2006 08:52:06 +0200, in comp.lang.c , jacob navia
<(E-Mail Removed)> wrote:

>Bill Pursell a écrit :
>> Which doesn't exist in standard C. lcc-win32 may provide
>> one, but it isn't standard C and it's generally a bad idea
>> to rely on a GC. If you are programming at a level where
>> you want a garbage collector, then you shouldn't be
>> programming in C. (My opinion.)

>
>C is for "macho" programmers that drink beer and
>are just backwards.


Thats not what he said, and as usual you post a silly reply which
serves no purpose except to damage the rest of your post and set
people against you.

>This is of course YOUR opinion. I beg to differ.


You could have posted this bit alone, and sounded rational instead of
stupid.

>Look dear, I use an automatic drive, and do not care about
>passing gears when driving you see?


Statistically, you're 14% more likely to have an accident in bad
weather in an automatic*.

>> I'm not aware of gcc support for a garbage collector for C. It
>> supports
>> garbage collection for objective-C, but I don't believe it provides
>> it for C.

>
>The garbage collector is "language agnostic" and will work for C,
>C++ or objective C in the same fashion.


I sincerely doubt this. Gathering garbage created by programmers
forgetting to delete objects or call destructors is somewhat different
to that created by programmers forgetting to call free, or pointing
pointers around randomly.

*or so a bloke in the pub told me. He's probably as reliable as
anyone.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      09-13-2006
Mark McIntyre wrote:
> <(E-Mail Removed)> wrote:
>

.... snip ...
>
>> Look dear, I use an automatic drive, and do not care about
>> passing gears when driving you see?

>
> Statistically, you're 14% more likely to have an accident in bad
> weather in an automatic*.


The next time you run out of fuel and stall on a railroad crossing,
and want to walk the car out of the way of the train with the
starter motor, please describe how you do that when equipped with a
slush box.

--
"I was born lazy. I am no lazier now than I was forty years
ago, but that is because I reached the limit forty years ago.
You can't go beyond possibility." -- Mark Twain



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      09-13-2006
CBFalconer wrote:
> Mark McIntyre wrote:
>
>><(E-Mail Removed)> wrote:
>>

>
> .... snip ...
>
>>>Look dear, I use an automatic drive, and do not care about
>>>passing gears when driving you see?

>>
>>Statistically, you're 14% more likely to have an accident in bad
>>weather in an automatic*.

>
>
> The next time you run out of fuel and stall on a railroad crossing,
> and want to walk the car out of the way of the train with the
> starter motor, please describe how you do that when equipped with a
> slush box.
>

slush box?

--
Ian Collins.
 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      09-13-2006
CBFalconer said:

> Mark McIntyre wrote:
>> <(E-Mail Removed)> wrote:
>>

> ... snip ...
>>
>>> Look dear, I use an automatic drive, and do not care about
>>> passing gears when driving you see?

>>
>> Statistically, you're 14% more likely to have an accident in bad
>> weather in an automatic*.

>
> The next time you run out of fuel and stall on a railroad crossing,


Having driven for a great many years, I am pleased to report that I have
never, ever run out of fuel. This is not mere luck. It is the result of
forethought.

Having driven for a great many years, I am pleased to report that I have
never, ever stalled on a level crossing. This is not mere luck. It is the
result of forethought.

The chance of my doing either of these is vanishingly small, and the chance
of doing both simultaneously is epsilon squared.

On the other hand, you wouldn't catch me driving an automatic, at least not
through choice.

--
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)
 
Reply With Quote
 
MotoK
Guest
Posts: n/a
 
      09-13-2006
Hello All,
Well i got some inputs like GC and logging utility.Thanks to all.

 
Reply With Quote
 
Spiros Bousbouras
Guest
Posts: n/a
 
      09-13-2006
MotoK wrote:

> Hello All,
> Well i got some inputs like GC and logging utility.Thanks to all.


You are off topic. This is a thread about "slush boxes".

 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      09-13-2006
Richard Heathfield wrote:
>
> On the other hand, you wouldn't catch me driving an automatic, at least not
> through choice.
>


Ahhh OK. I understand now why you are against the GC.

I drive an automatic, relaxed, no effort, the machine works for
me, not the other way around...

jacob
 
Reply With Quote
 
Richard Bos
Guest
Posts: n/a
 
      09-13-2006
jacob navia <(E-Mail Removed)> wrote:

> Richard Heathfield wrote:
> >
> > On the other hand, you wouldn't catch me driving an automatic, at least not
> > through choice.

>
> Ahhh OK. I understand now why you are against the GC.
>
> I drive an automatic, relaxed, no effort, the machine works for
> me, not the other way around...


In short, you can't drive. That's no shame, many people can neither
drive nor program competently, and yet be valuable members of society;
but do not try to lecture to those of us who can.

Richard
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there something similar to list comprehension in dict? Peng Yu Python 8 11-20-2009 08:37 PM
Re: Is there something similar to list comprehension in dict? Patrick Sabin Python 1 11-20-2009 09:29 AM
Ambiguity with Smart Pointers (Boost or similar) number774@netscape.net C++ 6 01-03-2008 05:30 PM
Is there a goto statement (or something similar)? Mike42 Java 21 11-14-2005 12:22 PM
Is there something similar to ?: operator (C/C++) in Python? Bo Peng Python 31 06-30-2005 06:19 PM



Advertisments