|
Reading a configuration file instead of hard-coding things is an example. Even just waiting until runtime to allocate an array qualifies.
When C++ calculates things at compile time, it's usually a case of using more memory to run faster, at least when templates are involved. And a DLL is the opposite, running slower to save memory.
|
|
|
|
|
You are right, configuration files would qualify.
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
I agree with second part about templates and DLL's, memory / speed trade offs.
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
Multix operating system was the mother of DLL's.
Multics - Wikipedia[^]
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
Greg Utas wrote: When C++ calculates things at compile time, it's usually a case of using more memory to run faster, at least when templates are involved.
I disagree with this. Where I'm using templates to do precomputed things, it's not increasing memory use at all, but simply flexibility of my API.
For example, an RGB565 pixel is 16 bits, with 5 bits for Red, 6 bits for Green and 5 bits for Blue
To pick off or set individual channels requires bitshifting and masking
I use templates to facilitate
A) Querying pixels, so you can do like rgb_pixel<16>::has_channel_names<channel_name::R, channel_name::G>::value (will be bool true )
B) Picking/Setting off arbitrary pixel channel data like px.template channel<channel_name::G>(); which returns the green channel
C) Doing bitmap manipulation using the binary footprint implied by the constructed pixels, which can have any number of channels with any sort of names - RGB is just one example)
None of this is about trading speed for memory.
It's about buying flexibility. Period.
There is no case in GFX where I use computed compilation to trade performance aspects. It's all about flexibility while maintaining the same kind of performance you get without it.
In fact, forgive me but I can't think of a situation like you describe.
To err is human. Fortune favors the monsters.
|
|
|
|
|
I'm not talking about your particular example.
Memory usage depends on how many instantiations of a template you end up creating. If a small number, doing things at compile time might actually yield a savings. But the way templates are generally used will produce multiple copies of more or less the same code unless the compiler is very clever. There is an Embedded C++ standard that removes templates (and exceptions and RTTI) for this reason, though most systems now have so much memory that I doubt many people still use it.
|
|
|
|
|
You're talking about binary size. I see. Yes there is some code bloat, but it all depends on what you're doing.
In some cases - surprisingly more than even I would have expected - you won't be duplicating any more code than you would by hand.
This code is a good example. There's virtually zero template overhead for multiple instantiations. It doesn't mean some code isn't duplicated, but you would have had to duplicate that duplicated code if you made each instantiation by hand.
htcw_tft_io/tft_spi.hpp at master · codewitch-honey-crisis/htcw_tft_io · GitHub[^]
Forgive me, because earlier I thought you were talking about runtime memory usage, not binary size.
I should add that while it's true in many cases that binary size increases memory usage, this is not true on most of the platforms I develop on these days. Hence your meaning in your assertion was completely off my radar.
To err is human. Fortune favors the monsters.
|
|
|
|
|
Precomputed sin tables. If you want to do sin computations it's a pretty complicated math formula for a computer. You can precompute tables to do your sins. You can use memory to hold those precomputed sins which you either computed on startup, or computed using the compiler and embedded in your executables .text section or whatever, but either way it ends up using RAM to hold it. Then when you want to compute a sin, it's a simple array lookup, at least assuming your operand is contained in the table.
To err is human. Fortune favors the monsters.
|
|
|
|
|
Precomputed trig, logs, etc. is pretty old school and very fast. If you have to do a lot of them and accuracy is not so critical, tables are the way to go. Most modern CPU's are usually fast enough to handle non-pre-computed math functions on a need to use basis. I am glad you brought this up. Gave me a reason to research this topic. Thanx
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
Math co-precessors for intel CPU's were at first a separate chip (really old days) then became built-in.
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
Wordle 386 6/6
⬜⬜⬜🟨⬜
⬜🟩⬜⬜⬜
🟨🟩⬜⬜🟨
🟨🟩⬜⬜🟨
🟨🟩⬜🟨🟨
🟩🟩🟩🟩🟩
Just made it.
|
|
|
|
|
Wordle 386 3/6
⬜⬜⬜⬜🟨
⬜⬜🟩🟩🟩
🟩🟩🟩🟩🟩
Love my starters!
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Wordle 386 4/6
🟨⬜⬜🟨⬜
⬜🟨⬜🟨🟨
🟨🟨⬜⬜🟨
🟩🟩🟩🟩🟩
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Wordle 386 4/6
⬜⬜⬜⬜⬜
🟩🟨⬜⬜⬜
🟩🟩🟩⬜🟨
🟩🟩🟩🟩🟩
Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
modified 10-Jul-22 2:49am.
|
|
|
|
|
Wordle 386 5/6
⬛🟨⬛⬛🟨
⬛🟨⬛🟨🟨
🟨🟩🟨⬛⬛
🟨🟩🟩⬛⬛
🟩🟩🟩🟩🟩
|
|
|
|
|
Wordle 386 5/6
🟨⬜⬜⬜⬜
⬜⬜⬜⬜🟨
⬜⬜🟨🟨⬜
🟨🟩🟩🟨⬜
🟩🟩🟩🟩🟩
Had to google the word after I guessed it.
|
|
|
|
|
Wordle 386 4/6*
⬜⬜🟩⬜🟨
🟨🟨🟩⬜⬜
⬜⬜🟩🟩🟩
🟩🟩🟩🟩🟩
Happiness will never come to those who fail to appreciate what they already have. -Anon
|
|
|
|
|
Wordle 386 5/6
⬛🟨⬛🟨🟨
🟨🟨🟨⬛⬛
⬛⬛🟨🟨🟨
⬛🟩🟩⬛🟨
🟩🟩🟩🟩🟩
|
|
|
|
|
Wordle 386 4/6
⬛⬛⬛⬛🟨
🟨⬛⬛⬛⬛
🟩🟨🟨⬛⬛
🟩🟩🟩🟩🟩
Get me coffee and no one gets hurt!
|
|
|
|
|
Wordle 386 4/6
⬜⬜⬜⬜🟨
⬜🟨⬜⬜🟨
🟨🟨⬜⬜⬜
🟩🟩🟩🟩🟩
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
Wordle 385 3/6
🟨🟨⬜🟨⬜
⬜⬜🟩🟩🟩
🟩🟩🟩🟩🟩
Three after a long time.
|
|
|
|
|
Wordle 385 6/6
🟨⬜⬜🟨🟨
🟩🟩🟨⬜🟨
🟩🟩🟩🟩⬜
🟩🟩🟩🟩⬜
🟩🟩🟩🟩⬜
🟩🟩🟩🟩🟩 Close one: I went for the wrong order with those last four!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Wordle 385 3/6
🟨🟨⬜🟨🟨
🟨🟨🟨⬜🟩
🟩🟩🟩🟩🟩
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Wordle 385 3/6
🟨⬜⬜🟨🟨
🟨⬜🟩🟩🟩
🟩🟩🟩🟩🟩
Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
Wordle 385 6/6
⬜⬜⬜⬜🟨
🟨⬜⬜⬜⬜
🟨⬜⬜⬜🟨
🟩🟨⬜🟨⬜
🟩🟩🟨⬜🟨
🟩🟩🟩🟩🟩
Phew, got lucky on that one.
|
|
|
|