C++ new operator - memory layout
c++, memory, oop
Solution
Yes, the memory will be continuous. In terms of allocation, it's the same as the `malloc` version, but there are several differences (calls to constructor, `new` doesn't return `NULL`, `malloc` doesn't throw exceptions, etc.`).
Note that you can't mix up `new[]` with `delete` or `free`, you have to use `delete[] objects` to free the memory.
Problem
Is the new operator guaranteed to allocate a continuous chunk of heap memory? I.e. is ``` objects=new Base[1024]; ``` in terms of memory allocation the same as ``` objects=(Base*)malloc(1024*sizeof(base)); ``` or can there be gaps?