有没有一种语言具有 C/C 的速度++但没有缓冲区溢出并且有垃圾收集器?
我正在寻找一种像 C 和 C++ 一样快速的编程语言,并且具有垃圾收集器并且不易出现缓冲区溢出。我正在寻找介于 Java/C# 和 C/C++ 之间的东西。有这样的语言吗?
I am looking for a programming language that is fast like C and C++ and has a garbage collector and is not prone to buffer overflows. I am looking for something between Java/C# and C/C++. Is there such a language?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查缓冲区溢出和收集垃圾是有代价的:如果您需要这些功能,那么您将无法获得 C/C++ 的速度。权衡。
在大多数类型的应用程序中,Java 和 C# 的速度非常非常接近 C++,因此除非您需要非常具体的东西,否则我建议您选择这两种语言中的一种。
如果您只需要一个 C++ 垃圾收集器,您可以在这里获取一个。
Checking for buffer overflows and collecting garbage has a cost: if you need these features, then you will not get the speed of C/C++. Tradeoff.
Java and C# are very, very close to C++ speed in most types of applications, so unless you need something very specific, I suggest you go with one of those 2 languages.
If you just want a garbage collector for C++, you can get one here.
您可以查看D。它是一种编译语言,除了垃圾收集和其他一些功能之外,还具有 C++ 的大部分功能。
You could take a look at D. It's a compiled language with most of the features from C++ in addition to garbage collection and some others.
语言“速度”高度依赖于应用程序。 JVM 对于某些类型的代码来说速度非常快——热点实际上可以比本机代码更快。另一方面,函数式风格和良好的优化可以让您用更少的代码获得良好的性能——通常 Haskell 应用程序在实践中与 C 中的应用程序一样快。
对于 Java/C# 和 C++ 的真正交叉,最好的地方是查看是D语言。它具有垃圾收集功能,以及对
malloc
和free
的可选访问,甚至可以实现 C 级性能的内联汇编。它具有足够的安全性,不易发生缓冲区溢出,但您仍然可以拥有它们。 http://www.digitalmars.com/d/2.0/index.html您始终可以对 C/C++ 进行垃圾收集,但这会付出代价。 Java、Haskell、ML,甚至 Python 都可以使用知道哪些值可能是指针的垃圾收集器,因此比使用 C、C++ 或 D 的收集器更快。
Language "speed" is highly application dependent. The JVM is darn fast for certain kinds of code--hot spot can actually be faster than native code. On the other hand, functional style and a good optimized can let you get good performance with less code--often Haskell apps are as fast in practice as ones in C.
For a real cross of Java/C# and C++ the best place to look is the D language. It has garbage collection, and optional access to
malloc
andfree
and even inline assembly for C level performance. It has enough safety to be less prone to buffer overflows, but you can still have them. http://www.digitalmars.com/d/2.0/index.htmlYou can always garbage collect C/C++, but it will cost you. Java, Haskell, ML, even Python can use garbage collectors that know what values might be pointers, so are faster than using a collector for C, C++, or D.