Yes.
The overhead associated with each memory allocation depends on the OS and whether the code is built with or without debugging symbols.
Regardless, there is positive overhead per each allocation. Hence, the overhead of allocating N objects in one call is substantially less than allocating one object each N times, specially when N is 10000000.
Take a look following code:
#include <stdlib.h>
#include <iostream>
struct Object
{
Object() : i(0) {}
int i;
};
int N = 1000000;
void test1()
{
Object* p = new Object[N];
}
void test2()
{
for (int i = 0; i != N; ++i )
Object* p = new Object;
}
int main(int argc, char** argv)
{
int i = atoi(argv[1]);
if ( i == 1 )
{
test1();
}
else
{
test2();
}
std::cout << "Enter a number: ";
std::cin >> i;
return 0;
}
Platform: cygwin32, Compiler: g++ without debugging symbols
Memory used for test1: 4,760K
Memory used for test2: 16,492K
Platform: Windows 7, 64 bit, Compiler: Visual Studio 2008 without debugging symbols
Memory used for test1: 4,936K
Memory used for test2: 16,712K
Platform: Windows 7, 64 bit, Compiler: Visual Studio 2008 with debugging symbols
Memory used for test1: 5,016K
Memory used for test2: 48,132K
There's also the extra book keeping that has to be done to make sure that the allocated memory is deallocated. The point of this exercise was to just demonstrate the overhead costs associated with the two ways of allocating memory.