Farooq Mela <[EMAIL PROTECTED]> wrote:
> 
> Hi,
> 
> Usually when I write programs, I have functions such as the following:
> 
> void *
> xmalloc(size_t size)
> {
>       <nice code>
> }
> 
> void *
> xrealloc(void *ptr, size_t size)
> {
>       <nice code>
> }
> 
> And then I use these instead of malloc and realloc throughout the
> program, and never have to worry about return values. Sometimes these
> functions also have additional cleanup they perform. Anyway, there are
> certain libc functions which also use malloc, such as getaddrinfo,
> vasprintf, etc. These may fail with errno = ENOMEM. In general, it is
> annoying to have to check the return values for these functions too.
> Would it not be convenient to set the memory allocator used by certain
> functions inside libc? I.E, be able to write:
> 
> set_allocator(xmalloc);
> set_reallocator(xrealloc);
> 
> >From then on, one would never have to worry about the functions running
> out of memory. I know that wrappers for functions which allocate memory
> can also be written, but I feel that my proposal would is in general a
> more convenient solution.
> 
> How do you guys feel about this?
> 
> -Farooq


 This would have probably been an outstanding idea when the
 C standard was being put together...  (and, who knows, somethine
 similar may very well have been proposed.)

 But,  let me point out that adding such a feature to the FreeBSD
 library doesn't mean you can dispense with your checks and/or
 wrapping functions.  As soon as your code needs to run on another
 platform, you'll need those checks...

 Such is the way of the world - when you have a standard, that's
 all you can expect from other systems...

        - Dave Rivers -

--
[EMAIL PROTECTED]                         Work: (919) 676-0847
Get your mainframe (370) `C' compiler at http://www.dignus.com


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to