Fun with calloc and malloc

Started by
2 comments, last by Sirveaux 20 years, 3 months ago
Is calloc(elementNumber, size) the same thing as calling malloc(elementNumber * size)? I know this works for dynamic arrays in C, but is there a standard C++ equivalent for handling them?
Advertisement
The new and delete operators. You could still use malloc or calloc, but it''d be considered bad practice.
Oh! That's right... I've used them before. I just completely forgot about them. Heh.

Oh, and one more thing: Does free() work with calloc()? Or do I have to use realloc() with a size of 0 to free memory allocated with calloc?

[edited by - Sirveaux on January 24, 2004 5:49:24 PM]
free works with calloc.

You can find out more by using google like so: free site:msdn.microsoft.com.

Which leads to free:

quote:
Remarks

The free function deallocates a memory block (memblock) that was previously allocated by a call to calloc, malloc, or realloc. The number of freed bytes is equivalent to the number of bytes requested when the block was allocated (or reallocated, in the case of realloc). If memblock is NULL, the pointer is ignored and free immediately returns. Attempting to free an invalid pointer (a pointer to a memory block that was not allocated by calloc, malloc, or realloc) may affect subsequent allocation requests and cause errors.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man

This topic is closed to new replies.

Advertisement