as i'm playing with linked list code today i was thinking this would be
a nice addition to the malloc/free and friends api:
int malloc_reserve(int size, int how, int arg);
the idea is that you would specify how much memory you're going to
allocate very soon, how it would be allocated (RESERVE_CALLS meaning
number of calls to malloc, RESERVE_AVG meaning average size) and the
arg for "how" (call count or average size respectively).
it would then return 0 if it can't, a reservation number >0 if it can.
when you hit the end of the code that malloc_reserve covered, you just
call malloc_unreserve with the reservation number which would free up
any extra memory it reserved.
the idea is that you can calculate an upper bound on the memory you're
going to allocate and then reserve it. then you can call malloc and
friends with no need to do out of memory checking.
the obvious downside is that you might incorrectly calculate the upper
bound.
kevin
--
kevin at suberic.net buffy: come on, can't you put your foot down?!
fork()'ed on 37058400 giles: it *is* down.
meatspace place: orbit buffy: one of these days you're going to have to
http://suberic.net/~kevin get a grown up car. --inca mummy girl
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!