title: Faster to malloc multiple small times or few large times?
body: <p>When using malloc to allocate memory, is it generally quicker to do multiple mallocs of smaller chunks of data or fewer mallocs of larger chunks of data?  For example, say you are working with an image file that has black pixels and white pixels.  You are iterating through the pixels and want to save the x and y position of each black pixel in a new structure that also has a pointer to the next and previous pixels x and y values.  Would it be generally faster to iterate through the pixels allocating a new structure for each black pixel's x and y values with the pointers, or would it be faster to get a count of the number of black pixels by iterating through once, then allocating a large chunk of memory using a structure containing just the x and y values, but no pointers, then iterating through again, saving the x and y values into that array?  I'm assuming certain platforms might be different than others as to which is faster, but what does everyone think would generally be faster?</p>