Wednesday, July 24, 2013

What Am I Missing?

Newsgroup: comp.lang.c++

Subject: Re: What Am I Missing?

From: Ian Collins <ian-news@...>

Date: Thu, 25 Jul 2013 11:21:24 +1200



Mike Copeland wrote:

> I have a lot of C-based code that I'm (slowly) converting to C++,

> STL, and what I hope to be code that's easier to manage. I'd also like

> to gain performance increases and reduced code - but I'm not really

> seeing the latter improvements. 8<{{

> As I think about it, there appear to be some trade-offs with either

> type of coding:

> 1. C-based strings require fixed (max) size declarations and runtime

> code to scan these character strings to determine size - so that

> operations can be made on them. There's overhead in both object file

> size and execution processing to deal with such data.

> 2. STL strings, on the other hand, are instantiated as object pointers

> that require runtime memory allocation(s), which might be done over and

> over as the data values change throughout execution. (That is, checks

> must determine if currently allocated data sizes are adequate, and

> deallocation/reallocation done if not. This might require substantial

> runtime logic to do for each and every string object.)



C++ strings (STL isn't an appropriate prefix) can also have a fixed size

reservation, just as C strings would have to be dynamically managed if

the initial size wasn't known. So there's no additional cost with C++

strings, but considerable savings in programmer effort!



> Thus, program object sizes should probably be smaller for C++

> programs, but C-based programs should generally be larger than

> corresponding C++ executables. I'm not seeing this phenomenon at all -

> in fact, the opposite seems true.



Define size. Fully optimised and stripped binary? Debug binary?



> I don't know if C++ programs execute any faster than C programs (I

> suspect they don't), and I don't know if any of my applications would

> expose this fact, either way.

> I do know that my C++ programs are invariably larger than their C-

> based versions.

> If there's no other factor in what I'm seeing, I guess the only real

> benefit to C++ and STL is ease of coding, debugging and maintenance.

> <sigh> Any thoughts?



Those are big benefits.



--

Ian Collins







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?50436-What-Am-I-Missing&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

No comments:

Post a Comment