Jump to content
  • Advertisement

Archived

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

Sirveaux

Fun with calloc and malloc

This topic is 5413 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!