I'm currently writing an embedded application in C where performance is critical.
Currently, I'm allocating lots of empty memory like this: calloc(1, num_bytes)
- however, I simply calculate num_bytes
as the product of a number of items and the size of each item earlier in the code as it's code that used to call malloc
.
calloc
seems unique in that it is the only memory allocation function of the -alloc family which takes two arguments for the size. Is there a good reason for doing this? Are there performance implications for specifying different arguments? What was the rationale in choosing this argument layout?