执行bash命令和获取输出用C [英] Executing bash command and getting the output in C

查看:163
本文介绍了执行bash命令和获取输出用C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我看到在互联网上的一些解决方案,所有这些基本上都是创建一个文件,但是我想将它们存储在字符数组。速度对于我来说真的很重要,我不想花任何时间,硬盘驱动器上工作。因此,的popen()不是一个真正的解决方案给我。

Hello I have seen some solutions on the internet, all of them are basically creating a file, however I want to store them in an array of char. Speed is really important for me and I don't want to spend any time for working on hard drive. So popen() is not a real solution for me.

推荐答案

永远不要忘记Knuth的话说,premature优化是一切罪恶的根源。做任何事情之前,不要担心性能,直到它的事项,然后的测量的。除了极少数情况下,你的时间值大于计划的成本运行的高得多。

Never forget Knuth's saying that "premature optimization is the root of all evil". Don't worry about performance until it matters, and then measure before doing anything. Except for very rare situations, the value of your time is much higher than the cost of the program runs.

乔恩Bentley的编写高效的程序(遗憾的是绝版的,在他的 编程珠玑一章是一个总结)是如何使程序运行更快(如果它是值得的)的详细讨论;而只能作为最后的措施,挤出的表现最后可能的2%,它建议像你提出使用变化(减少运行时间减少了一半后)。引用的书中包括那是一个完整的浪费性能优化的一些非常有趣的战争故事(优化未使用过code,oprimize的code运行在操作系统的旋转因子大拇指,... )。

Jon Bentley's "Writing efficient programs" (sadly out of print, in his "Programming Pearls" one chapter is a summary) is a detailed discussion on how to make programs run faster (if it is worthwhile); and only as the very last measure, to squeeze out the last possible 2% of performance (after cutting run time down by half) it recommends using changes like you propose. The cited book includes some very entertaining war stories of "performance optimizations" that were a complete waste (optimize code that isn't ever used, oprimize the code run while the operating system twiddles its thumbs, ...).

这篇关于执行bash命令和获取输出用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆