5 ms·
No, the compiler avoids unecessary work unless you ask it to.
by fla 12y ago
No, the compiler avoids unecessary work unless you ask it to.
- mamcx 12y agoSo, when is necesary to let the garbage without clean it? For what is usefull?
- stephencanon 12y agostruct Foo foo; foo_init(&foo, bar, baz, quux); If the language made the first line zero-initialize foo, we'd write the whole of the structure twice; it would be zero-initialized just to be overwritten by foo_init. For many cases, this minor inefficiency would not be a concern. For some uses it would be a major problem. If you do need to zero-initialize foo, you can do that easily: struct Foo foo = { 0 };
- mamcx 12y ago"major problem"? Like when? Sorry to ask this. I have lived outside the C madness this 18 years (pascal and other more saner stuff..), except now using obj-c/js and is crazy the amount of small weird stuff it have.. This make my ask: From where it get the garbage?
- pstuart 12y agoMemory returned to the heap. It's recycled, right?
- mamcx 12y agoAh! I get it. Some If the program have 100 "cells" of memory, the first time it get blank, the second what was there before? Clear the data is costly in the long run? I have read yesterday about data oriented design and it make me understand that now is costly to access memory.
- pstuart 12y agoThat's exactly it. If you're going to dump data into that memory that is guaranteed to overwrite whatever is already there, then there's no point in wasting cycles zeroing it first.