Re: memorize from "Daniel Koepke" at Oct 2, 97 11:44:10 pm

From: Andrew Helm (ashe@IGLOU.COM)
Date: 10/03/97


On Fri, 3 Oct 1997, Akuma/Chris Baggett/DOOMer wrote:
>
> Andrew Helm wrote:
> >You know better than to say that. calloc() initializes the
> >allocted memory to zero while malloc() doesn't garantee anything
> >about it's contents. That and the fact that calloc() is much
> >slower than malloc() makes for a significant difference
> >between the two. They are not interchangeable. Code that uses
> >calloc() (eg- circle) often calloc()'s the memory for structures
> >instead of malloc()'ing it and seperately initialing each field
> >of the structure.
>
>   well, if everything is always set to something already (it should be)
> why not use Malloc no matter what?

Exactly. :)
The point is that malloc does not set everything to something, that is,
it returns the memory with whatever garbage was in it. Using calloc()
one can skip the initialization of variables to zero since it's already
done for you. It's a great way to protect yourself from stupid mistakes
such as adding a new field to a structure but forgetting to add a line
of code that initializes it with the rest of the fields. The reason why
you shouldn't always use calloc() instead of malloc() is merely a matter
of speed.

[snip]


Akuma/Chris Baggett/DOOMer wrote:
question here, doesn't Circle use the CREATE() macro?
which in turn uses  _c_alloc()?  NOT _m_alloc()?

Daniel Koepke wrote:
Uhm, what's the point?  calloc() is just malloc() that takes
an extra parameter.  They do (essentially) the same thing.

Andrew Helm wrote:
[see quoted paragraph above]

Daniel Koepke wrote:
Hence the word *essentially*...
[endquote]

calloc() is not just a malloc() that takes an extra parameter,
nor do calloc() and malloc() do essentially the same thing.
Someone who does not already know the differences between the
two functions will not gain any insight or new information
from your post. In fact, because your post inadequately
stresses the differences between the two there is the very
real danger that the aforementioned person will come away
with the incorrect assumption that the two functions are
essentially the same and can be used interchangeably.


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/08/00 PST