Sunday 7 July 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...