>would it be so complex ? >what about having the first part of the array static, and only add parts >if we really need to ? >struct desc { >long count; >struct desc *next; >foobar descs[0]; >} > >with the first would be inlined in process descriptors or such, and a FOREACH >macro would do > > >({ >foobar *fd; >struct desc *current = &proc[i].fd; >while (current) { >int i; >for (i=0; i < current->count; i++) { >if (compare(current->descs[i], d)) > goto found; >} >current = current->next; >} >NULL; > >found: > >current->descs[i]; >}) > >Of course that's not even quite O(1), and hashing would be harder... >but in the usual case we would not need anny malloc() since the first block >is inlined, and the overhead isn't big. I have seen this before. The problem is deciding what count should be. Pretend that you are the kernel for a minute. We allocate (say) 5 file descriptors in that first block (that is inline). You get a request for another one (#6). Obviously you have to make a new block. How many should you allocate? Truth is, we don't know. It could be an app that uses 6. Or 600. There is no real way to know. >What about using fixed size arrays, with sizes tweakable at boot >(in ~/config/settings/kernel/drivers/kernel) ? >would be as fast, just need a malloc(), still simple code... >and in case we want to run IceCast for 10000 users just change the MAX_FD >in the kernel prefs and reboot :) Very Linux. :-/ Probably better than the way that Be had it (you get N of them, period), but still not the way that I would like to do it. >Or we could as well be able to change some (MAX_FD) at runtime, so increasing >it just before running critical progs (there is a defined interface for this, >called ulimit()). This is more tempting. >Of course it's not as good as if the system would deal itself with this... >We must keep in mind we are building a desktop OS, not a server :^) Yes. But sometimes users want to do these things, too. And for the system to fail (as R5 will, I think) on too many is far from ideal. >Also remember MAX_FD is defined in POSIX headers, so dynamic growing is maybe >not worth it. But what if someone uses the Storage Kit?