Reputation: 2553
Currently working on a code I realized that it used to call malloc
multiple times (around 10 million calls) and allocated small chunks (around 10 bytes) every time.
I changed the code a little and instead of calling malloc
10 million times I now call malloc
10 times allocating a large chunk of memory (10 million bytes) every time.
With this change I noticed that peak memory consumption of my code changed from ~15 GB to ~14 GB.
Why is this happening? Does malloc
allocates some extra chunk with every call?
Upvotes: 2
Views: 1334