3 ms·
As Linus might say, "this is complete idiocy". Even if you need to write a lot of data, the correct way is to write it in blocks using a fixed-size buffer, not
by userbinator 8y ago
As Linus might say, "this is complete idiocy".
Even if you need to write a lot of data, the correct way is to write it in blocks using a fixed-size buffer, not try to stuff the whole thing in at once...
Maybe it's not possible to completely eliminate all dynamic allocation, but striving to make your code O(1) space (and time) should be a relatively important goal.
- Someone 8y agoThe choice may be incorrect, but the alternatives aren’t all around optimal, either. A logging system must write each message atomically. That can be done when “writing in blocks using a fixed-size” buffer, but it complicates code, and, I guess, would introduce additional latency (something you really do not want in a logging system) when processes race for using the logging system.
- Quekid5 8y agoDo you have a close-to-perfect implementation, perchance? Any logging implementation I have ever seen is full of tradeoffs along all sorts of axes. At some point something has to give. Examples: Your log cannot accept more messages (maybe it's a local disk), what do you do? Do you store it in memory? Do you throw it away and record that you threw messages away? What happens if the machine dies before you can record the failures? Are there some log messages that are important enough to actually halt the application? etc. etc. EDIT: ... and let's not even get into remote logging. It's actually a really complicated problem and not enough people appreciate that.