智能指针:C中有类似于智能指针的东西吗? [英] Smart Pointers: Is there something similar to smart pointers in C?
问题描述
嗨专家,
我刚刚加入这个小组并想知道一些事情:
是否有与C中的智能指针类似的东西或者
防止C程序中的内存泄漏。
问候
MotoK
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
推荐答案
MotoKaécrit:
MotoK a écrit :
嗨专家,
我刚刚加入了这个小组,我想知道一些事情:
C中是否有类似于智能指针的东西,或者是什么?
防止C程序中的内存泄漏。
问候
MotoK
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
还有更好的东西:
a垃圾收集器。
使用垃圾收集器不需要智能指针,
构造函数,析构函数,奇怪的语言结构等等。
构造函数再次成为他们应该始终如此:
a函数这是在初始化数据结构时编写的。
大多数情况下都不需要析构函数,因为内存是自动回收的。$ / b。
>
最受欢迎的垃圾收集器是Boehm的垃圾收集器。一些编译器如
lcc-win32在标准发行版中提供GC。其他编译器
支持它,特别是GCC,它可以在任何情况下使用。
jacob
There is something much better:
a garbage collector.
Using a garbage collector obviates the need for smart pointers,
constructors, destructors, weird language constructs, etc etc.
The constructors are again what they should always have been:
a function that is written when needed to initialize a data structure.
The destructors aren''t needed in most cases since memory is
automatically reclaimed.
The most popular garbage collector is Boehm''s one. Some compilers like
lcc-win32 provide a GC in the standard distribution. Other compilers
support it, notably GCC, and it can be used in any situation.
jacob
jacob navia写道:
jacob navia wrote:
MotoKaécrit:
MotoK a écrit :
我刚刚加入了这个小组并想知道一些事情:
是否有与C中的智能指针类似的内容或某些内容来防止C程序中的内存泄漏。
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.
还有更好的东西:
垃圾收集器。
There is something much better:
a garbage collector.
标准C中不存在.lcc-win32可能提供
一,但它不是标准C和依靠GC,通常是一个坏主意
。如果你想要一个你需要垃圾收集器的级别编程,那么你就不应该用C编程
。(我的意见。)需要的东西。
智能指针的位置在C中是一个智能程序员。
你自己跟踪这些事情。
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.) The thing that takes
the place of a "smart pointer" in C is a "smart programmer".
You keep track of these things yourself.
使用垃圾收集器不需要智能指针,
构造函数,析构函数,奇怪的语言结构等等。
Using a garbage collector obviates the need for smart pointers,
constructors, destructors, weird language constructs, etc etc.
垃圾收集器*是*一个奇怪的语言结构 ;
A garbage collector *is* a "weird language construct".
最受欢迎的垃圾收集器是Boehm的垃圾收集器。一些编译器如
lcc-win32在标准发行版中提供GC。其他编译器
支持它,特别是GCC,它可以在任何情况下使用。
The most popular garbage collector is Boehm''s one. Some compilers like
lcc-win32 provide a GC in the standard distribution. Other compilers
support it, notably GCC, and it can be used in any situation.
我不知道gcc对C垃圾收集器的支持。它
支持
Objective-C的垃圾收集,但我不相信它为C提供了
它。
-
Bill Pursell
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.
--
Bill Pursell
Bill Pursellaécrit:
Bill Pursell a écrit :
jacob navia写道:
jacob navia wrote:
>> MotoKaécrit:
>>MotoK a écrit :
>>>我刚加入此群组并且想要了解一些事情:
在C语言中是否存在类似于智能指针的东西,以防止C程序中的内存泄漏。
>>>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.
还有更好的东西:
垃圾收集器。
There is something much better:
a garbage collector.
标准C中不存在.lcc-win32可能提供
一个,但它不是''标准C,依靠GC,通常是一个坏主意
。如果你想要一个你需要垃圾收集器的级别编程,那么你就不应该用C编程。(我的意见。)
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代表男子气概喝啤酒的程序员和
只是倒退。
这当然是你的意见。我不同意。
Yes of course!
C is for "macho" programmers that drink beer and
are just backwards.
This is of course YOUR opinion. I beg to differ.
需要
来代替智能指针的地方在C中是一个智能程序员。
你自己跟踪这些事情。
The thing that takes
the place of a "smart pointer" in C is a "smart programmer".
You keep track of these things yourself.
亲爱的,我使用自动驾驶,并不关心
开车时你会看到飞机吗?
如果我们有电脑供他们做麻烦的麻烦工作,>
不是我。我不会尝试使用我的大脑来完成他们的工作来超越计算机!
Look dear, I use an automatic drive, and do not care about
passing gears when driving you see?
If we have computers is for THEM to do the mind numbing work,
not me. I do not try to outsmart a computer by
using MY brain to do THEIR work!
>
>
>>使用垃圾收集器不需要智能指针,构造函数,析构函数,奇怪的语言结构等等。
>>Using a garbage collector obviates the need for smart pointers,
constructors, destructors, weird language constructs, etc etc.
垃圾收集器*是*一个奇怪的语言结构。
A garbage collector *is* a "weird language construct".
打扰一下,但是你是错误的:
原型:
void * GC_malloc(size_t);
用法:
char * buffer = GC_malloc(BUFSIZ);
什么是奇怪的语言结构在那里???
垃圾收集器绝对没有任何新的语言变化。你只需使用GC_malloc
而不是malloc,忘记免费并链接
提供的库。
这一切都是100 %标准C.
Excuse me but you are dead wrong:
prototype:
void *GC_malloc(size_t);
usage:
char *buffer = GC_malloc(BUFSIZ);
WHAT is a "weird language construct" in there ???
The garbage collector imposes absolutely no
new language changes at all. You just use GC_malloc
instead of malloc, forget about free and link with
the provided library.
All this is 100% standard C.
>
>
>>最受欢迎的垃圾收集器是Boehm的垃圾收集器。一些编译器如
lcc-win32在标准发行版中提供GC。其他编译器支持它,特别是GCC,它可以在任何情况下使用。
>>The most popular garbage collector is Boehm''s one. Some compilers like
lcc-win32 provide a GC in the standard distribution. Other compilers
support it, notably GCC, and it can be used in any situation.
我不知道gcc对C垃圾收集器的支持。
支持
目标C的垃圾收集,但我不相信它提供了
它用于C.
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.
垃圾收集者是语言不可知的并且将以相同的方式为C,
C ++或目标C工作。
The garbage collector is "language agnostic" and will work for C,
C++ or objective C in the same fashion.
>
- -
Bill Pursell
>
--
Bill Pursell
这篇关于智能指针:C中有类似于智能指针的东西吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!