Re: Difference?
From: Mark McIntyre (markmcintyre_at_spamcop.net)
Date: 02/26/04
- Next message: Christian Bau: "Re: Efficiency of math.h"
- Previous message: Chris Torek: "Re: strtoul bug (was Fibonacci number)"
- In reply to: Mohanasundaram: "Re: Difference?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 25 Feb 2004 23:11:08 +0000
On 24 Feb 2004 21:19:07 -0800, in comp.lang.c , mohanasundaram@msn.com
(Mohanasundaram) wrote:
>Hi All,
>
> After reading all the postings in this thread I have a query in
>my mind. If there is no big difference between malloc and calloc then
>why there exists two functions for memory allocation which can be
>achieved by one sigle function
Since zeroing out memory is often a Good Thing:
malloc might be considered fast-but-dirty.
calloc might be considered slow-but-safe.
This is a simplification, and of course you can achieve calloc with a
malloc/memset pair. but we assume that the compiler writer has access to
some optimised way of doing calloc which is more efficient than
malloc/memset, and since memory operations are often heavily used in C,
optimised ways to do them are a Good Thing too.
By the way, you could use the same logic for putc & puts, scanf & sscanf,
and probably quite a few other C features - including integer
multiplication....
-- Mark McIntyre CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html> CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html> ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
- Next message: Christian Bau: "Re: Efficiency of math.h"
- Previous message: Chris Torek: "Re: strtoul bug (was Fibonacci number)"
- In reply to: Mohanasundaram: "Re: Difference?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|