Sunday, July 7, 2019

c - Malloc equivalent for calloc

It's been a white since I've written for Microcontrollers, and I'm trying to refactor some code to work on such a device, in C.


I have a line of code:


Pieces = calloc(ARRAYSIZE, sizeof(struct piece));

http://www.cplusplus.com states that calloc:



Allocates a block of memory for an array of num elements, each of them size bytes long



Would the equivalent malloc operation then be:


Pieces = Malloc(ARRAYSIZE*sizeof(struct piece));

Disregarding that the bits haven't been set to 0, isn't that about the same? Or would I have to allocate a block of memory for ARRAYSIZE times?


Hope you can help.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...