3 ms·
Saving 8 bytes, and saving a few cycles by scanning rather than counting... is an argument for using NUL-terminated strings as an optimization in specialized ci
by rectang 5y ago
Saving 8 bytes, and saving a few cycles by scanning rather than counting... is an argument for using NUL-terminated strings as an optimization in specialized circumstances.
In the common case, the extra 8 bytes and the cycles saved (if any) don't matter — and are not worth the sacrifice of making it harder to program correctly.
- kevin_thibedeau 5y ago> the extra 8 bytes and the cycles saved (if any) don't matter You wouldn't last in embedded development with that sort of attitude. When you're nearly out of RAM you can't afford to waste overhead of fat strings.
- pkaye 5y agoNot every embedded system is memory constrained these days.
- rectang 5y agoIndeed. And besides, didn't I account for precisely that scenario? Memory-constrained embedded development is a specialized situation that could call for using NUL-terminated strings.
- pjmlp 5y agoI was using Turbo Basic, Turbo Pascal, Turbo C++ (with C++ collections), and Clipper on MS-DOS, with 640 KB of memory. It was just fine, then there are those that nowadays even toy with C++17 on C64. “Rich Code for Tiny Computers: A Simple Commodore 64 Game in C++17” https://www.youtube.com/watch?v=zBkNBP00wJE https://www.youtube.com/watch?v=zBkNBP00wJE Really, unless we are talking about PIC and AVRs with like 4KB, we are optimizing for the wrong target.
- mh7 5y agoYou can't afford to waste cycles on O(n) strlen either.