设为首页 加入收藏

TOP

4.4 A C++ Implementation(4)
2013-10-07 14:27:09 来源: 作者: 【 】 浏览:63
Tags:4.4 Implementation

图4.4 A C++(www.cppentry.com) Implementation(8)  
Our test program is a simple variant of the earlier one:

图4.4 A C++(www.cppentry.com) Implementation(9)  

The usage is different than with the C version, though only in a minor way. Depending on the compiler, the C++(www.cppentry.com) version is anywhere from 40 percent to four times slower than the C version on a large input file of 30,000 lines with about 25 fields per line. As we saw when comparing versions of markov, this variability is a reflection on library maturity. The C++(www.cppentry.com) source program is about 20 percent shorter.

Exercise 4-5. Enhance the C++(www.cppentry.com) implementation to overload subscripting with operator [] so that fields can be accessed as csv[i].

Exercise 4-6. Write a Java version of the CSV library, then compare the three implementations for clarity, robustness, and speed.

Exercise 4-7. Repackage the C++(www.cppentry.com) version of the CSV code as an STL iterator.

Exercise 4-8. The C++(www.cppentry.com) version permits multiple independent Csv instances to operate concurrently without interfering, a benefit of encapsulating all the state in an object that can be instantiated multiple times. Modify the C version to achieve the same effect by replacing the global data structures with structures that are al- located and initialized by an explicit csvnew function.


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇3.6 C++(1) 下一篇4.4 A C++ Implementation(3)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: