Paul G. Allen wrote:
Andrew Lentvorski wrote:
Paul G. Allen wrote:

So, the way Linux does it is not bad at all, but the way programmers fail to initialize the memory as soon as it's allocated *is* bad. Allocate the memory and initialize it when it's allocated, not later on when you *might* use it. That way, it's there up front, before the long computation, and there's no surprises half way through. (This is why the C or C++ compiler warns about uninitialized objects.)

You do embedded software?  Right?  And *still* make that statement?

Yes, and I can safely say that 100% of my embedded software has never been released with a bug. Allocating memory to an object in ANY system without properly initializing it to a known state is BAD BAD BAD. Especially in a complex system.

I have fixed lots of embedded software written by others that failed to do this, and in the process fixed bugs in said software. I've also fixed PC software that failed to do this.

And I have had to do the exact opposite. I had to remove an initialization loop on an embedded ARM7 system that wrote zeros to memory that was being tracked by a bitvector map precisely because writing to memory was so slow. Initializing the memory was completely taken care of by initializing the bitvector, yet they wasted huge chunks of time zeroing it out. Repeatedly.

I have also had to remove initialization from memory systems in which the data structure was carefully chosen to be O(k) in memory based upon the number of *intersections* (normally very small) rather than O(n) in the number of objects (normally very large). Writing all zeros to the memory which handled the sweepline queue (which had a very nice implementation that grew into memory gradually in an amortized manner using sentinels) changed the algorithm from time O(k*n) (k intersections touched * n objects touched--effectively O(n) in most cases) to O(n^2) (basically, the algorithm doesn't run). Removing that initialization made a huge difference.

And, finally, my best counter example to your "write zeros" argument is sitting in practically every operating system. *Nobody* writes all zeros to a disk anymore. Ever. They zero out the metadata and leave the garbage on disk until they overwrite it.

Space does not have to be zeroed to be initialized.

-a






--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to