difference between calloc() and malloc()

J

James Kanze

James Kanze wrote:

[...]
That is an interesting distinction. Do you happen to know of
any modern platforms for which "zero initialized" POD objects
require memory with non-zero bit-patterns?

Off hand, no, but that doesn't mean that one would surprise me.
I spent some years working with microprocessor design teams, and
0xdeadbeef was a common starting value for buses during simulations, to
make it clear that no value had yet been assigned to the bus. The only
time I've seen even a vaguely similar technique used in software is for
the magic numbers that sometimes identify file types, e.g. the
0xcafebabe at the beginning of Java .class files.

I'm certain that I've seen it somewhere. I use it in my debug
operator new/operator delete, but I certainly didn't invent it.
 
R

Ron Natalie

Victor said:
new constructs objects but malloc and calloc reserve raw memory;
different...

Well, malloc and calloc are just 'new char[]' and 'new char[]()'.
They don't "reserve raw memory" since there is no "raw memory" in
C++.

V
The are NOT just new char[].
They allocate chars from the C library free store.
The only difference with calloc is that it multiples the two args
together (this is one those attrocious carry over's from the so-called
portable IO library like the stdio funcs that should have never been
adopted by any sane language) and zeros the returned memory.

Your C++ allocation functions might allocate from the same arena, then
again they might not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,233
Latest member
AlyssaCrai

Latest Threads

Top