News for hackers. Stuff that matters.
Re:Transmission torrent client ported to C++ by rwmj on Sunday September 12, 2021 @05:13PM (#28505012)
Just built both versions for you. Edit: Please note the C++ code change doesn't actually use the STL, it really just changes the compiler and code style in a few places. So I don't think this represents any argument for or against C vs C++.

  -rwxr-xr-x. 1 rjones rjones 4167912 Sep 12 22:09 build-c++/gtk/transmission-gtk
  -rwxr-xr-x. 1 rjones rjones 3997408 Sep 12 22:12 build-c/gtk/transmission-gtk

  -rwxr-xr-x. 1 rjones rjones 3130352 Sep 12 22:09 build-c++/daemon/transmission-daemon
  -rwxr-xr-x. 1 rjones rjones 2959640 Sep 12 22:12 build-c/daemon/transmission-daemon

  build-c++/utils/:
  total 12156
  drwxr-xr-x. 6 rjones rjones    4096 Sep 12 22:08 CMakeFiles
  -rw-r--r--. 1 rjones rjones    5653 Sep 12 22:08 cmake_install.cmake
  -rw-r--r--. 1 rjones rjones     289 Sep 12 22:08 CTestTestfile.cmake
  -rw-r--r--. 1 rjones rjones   13793 Sep 12 22:08 Makefile
  -rwxr-xr-x. 1 rjones rjones 3082448 Sep 12 22:09 transmission-create
  -rwxr-xr-x. 1 rjones rjones 3066256 Sep 12 22:09 transmission-edit
  -rwxr-xr-x. 1 rjones rjones 3182928 Sep 12 22:09 transmission-remote
  -rwxr-xr-x. 1 rjones rjones 3073952 Sep 12 22:09 transmission-show

  build-c/utils/:
  total 11496
  drwxr-xr-x. 6 rjones rjones    4096 Sep 12 22:12 CMakeFiles
  -rw-r--r--. 1 rjones rjones    5645 Sep 12 22:12 cmake_install.cmake
  -rw-r--r--. 1 rjones rjones     287 Sep 12 22:12 CTestTestfile.cmake
  -rw-r--r--. 1 rjones rjones   13725 Sep 12 22:12 Makefile
  -rwxr-xr-x. 1 rjones rjones 2917136 Sep 12 22:12 transmission-create
  -rwxr-xr-x. 1 rjones rjones 2895128 Sep 12 22:12 transmission-edit
  -rwxr-xr-x. 1 rjones rjones 3014872 Sep 12 22:12 transmission-remote
  -rwxr-xr-x. 1 rjones rjones 2901832 Sep 12 22:12 transmission-show
Re:Transmission torrent client ported to C++ by ComputerGuru on Sunday September 12, 2021 @09:18PM (#28506827)
I think you’d have to strip the binaries to account for debug symbol differences.
Re:Transmission torrent client ported to C++ by atrn on Sunday September 12, 2021 @09:54PM (#28507050)
size(1) exists to provide the actual information. File sizes are only a rough indicator.
Re:Transmission torrent client ported to C++ by rwmj on Monday September 13, 2021 @03:25AM (#28508738)

     text    data     bss     dec     hex filename
   920576   11508    4152  936236   e492c build-c++/gtk/transmission-gtk
   912575   11644    4120  928339   e2a53 build-c/gtk/transmission-gtk
Re:Transmission torrent client ported to C++ by 10000truths on Sunday September 12, 2021 @06:48PM (#28505758)
What compiler flags did you use? Perhaps -Os would even things out a little more.
Re:Transmission torrent client ported to C++ by usr1106 on Monday September 13, 2021 @01:32AM (#28508130)
Why would anyone want to optimize for space? On a halfway modern PC at least, some really embedded platform might be a different story.
Re:Transmission torrent client ported to C++ by ameixaseca on Monday September 13, 2021 @11:44AM (#28512923)
Cache-friendliness; applies to any platform.

And it's "optimize for size", by the way.

Re:Transmission torrent client ported to C++ by usr1106 on Tuesday September 14, 2021 @02:45AM (#28521163)
Right, in certain cases. But here it's a networking application. So memory accesses won't be your bottleneck.
Re:Transmission torrent client ported to C++ by rwmj on Monday September 13, 2021 @03:27AM (#28508747)
gcc-11.2.1-1.fc35.x86_64 with whatever defaults the upstream project chooses.
Re:Transmission torrent client ported to C++ by junon on Monday September 13, 2021 @05:13AM (#28509259)
Did you run CMake with -DCMAKE_BUILD_TYPE=Release ?
Re:Transmission torrent client ported to C++ by rwmj on Monday September 13, 2021 @07:17AM (#28510039)
No, with -DCMAKE_BUILD_TYPE=RelWithDebInfo
Re:Transmission torrent client ported to C++ by junon on Monday September 13, 2021 @07:25AM (#28510088)
Right, and C++ is definitely going to have more debug info because of longer symbol names.

Test the two with Release instead. That will give you real results.

Re:Transmission torrent client ported to C++ by userbinator on Sunday September 12, 2021 @05:31PM (#28505186)
Thanks for the proof. Over 100k increase on average. Not surprising.

...and people wonder why software gets slower and bigger over time while doing the same thing. We even get HN articles about that semi-regularly.

Re:Transmission torrent client ported to C++ by stjohnswarts on Sunday September 12, 2021 @07:53PM (#28506306)
Unless you're on a limited embedded platform 100k of size increase in a binary is basically nothing these days or any pc/mac built in the past 20 years. Also equating bigger to slower in binaries as a truism is usually a fallacy.
Re:Transmission torrent client ported to C++ by hoseja on Monday September 13, 2021 @02:43AM (#28508486)
Are you actually being serious? Less than 3% increase warrants such a reaction?
Re:Transmission torrent client ported to C++ by userbinator on Monday September 13, 2021 @09:24AM (#28511166)
Will it ever decrease by 3%?

The amount of increase is irrelevant if it continues in the same direction.

Re:Transmission torrent client ported to C++ by rwmj on Sunday September 12, 2021 @05:41PM (#28505269)
A question that I'd like to ask a C++ expert: If you use any STL container, is it always the case that the whole thing is templated, therefore effectively compiled and statically linked into the binary? Or will part/all of it come from functions in the dynamically linked libstdc++.so?
Re:Transmission torrent client ported to C++ by bregma on Sunday September 12, 2021 @07:08PM (#28505939)
libstdc++.so (and libc++.so if you're bent that way) contain the standard stream objects, some standard string functions specialized on `char`, some threading and synchrony support and important parts of the C++ language runtime (eg. a default ::operator new, some of the exception unwinding and RTTI mechanisms). And that's it. It's actually fairly small and basic.

Pretty much everything else in the C++ standard library is template code in headers and gets instantiated when needed. You may end up having identical templated functions emitted into several different translation units and the linker will chose one at link time, which is one major reason why C++ is slower to build.

Only template functions that are actually used get instantiated. If you include a header with a gazillion templated functions (namespace level or member functions, it doesn't matter) you are most likely to end up with only one or two instantiated in your binary. Templates are like a cookbook, and just because Larousse has 10,000 recipes does not mean that's how much you're going to eat at every meal. Consider there is virtually an infinite number of possible instantiations for every template.

Re:Transmission torrent client ported to C++ by password4321 on Sunday September 12, 2021 @08:25PM (#28506523)
I guess it depends on your definition of small... VSCode recently mentioned a 10MB hit to statically link the libcxx library from Chromium to dodge issues running on older platforms.

Edit: libcxx from Chromium, not libstdc++

https://github.com/microsoft/vscode/pull/129360#issue-952350...

> The increase in bundle size is significantly small (~10MB).

Re:Transmission torrent client ported to C++ by 10000truths on Sunday September 12, 2021 @06:52PM (#28505792)
That depends on how the standard library is implemented. I wouldn’t be surprised if libc++ or libstdc++ used explicit template instantiations for STL containers of primitive types, e.g. std::vector<int>.
Re:Transmission torrent client ported to C++ by pjmlp on Monday September 13, 2021 @02:29AM (#28508404)
Here, targeting Commodore 64 with C++17.

https://www.youtube.com/watch?v=zBkNBP00wJE

Re:Transmission torrent client ported to C++ by kevindong on Sunday September 12, 2021 @08:46PM (#28506648)
100k bytes = ~98 KB.

That's not material.