Archived

This topic is now archived and is closed to further replies.

Sirveaux

Fun with calloc and malloc

Recommended Posts

Sirveaux    122
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?

Share this post


Link to post
Share on other sites
Sirveaux    122
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]

Share this post


Link to post
Share on other sites
LessBread    1415
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.

Share this post


Link to post
Share on other sites