You're welcomeeekee wrote:@vvaltchev: I'm thankful for your detailed explanation too. I'm thinking of a single-language OS. If this language is strongly typed, your point #1 would apply to 100% of allocations. I'm also happy to hear your buddy allocator wasted surprisingly little memory even before usage optimization.
It would be great if #1 could apply to 100% of the cases. But sometimes, enforcing that is "impossible" or inconvenient.
A few examples.
1. How to allocate strings? You can always allocate their maximum size but, are you OK with that?
2. Suppose you're implementing a container (e.g. ring buffer). Container's code is used by a variety of callers, in different subsystems, and the buffer size is a parameter. How can it become known at compile-time? Unless you wanna do the things C++ style, by having everything in headers (e.g. templates), the buffer size cannot be known at compile-time. Note: C++ templates are VERY bad, especially in kernels because they duplicate the code. "Compile-time" is often good, but sometimes terrible. It's a waste to duplicate your rb_write() for example, for every different buffer size. And it's not only about code size, it's about performance as well. The bigger the text section is, the less instruction cache locality there will be. That means more icache misses, and slower code execution.
3. Suppose you have to allocate a buffer which size is decided by the user space. It's impossible to have a compile-time value. OK, it's not impossible, but you'd have to allocate page by page. In that case, you won't get a contiguous chunk, though. Therefore, you'll have also to map all those pages somewhere in the virtual memory, in order to have your contiguous buffer. That's pretty slow.
Anyway, what do you mean with a "single-language OS"? I'm curious.