I want to use malloc as it’s memory assignment happens in O(1) rather than O(n) with the following code:
MyQuickInitArray(int size)
{
A = new T[size];
}
When A is of type:
T* A
I thought initializing an array of pointers will take O(1) because pointers are primitives but i doubled checked and the code above actually goes size times to the constructor of T. If this problem can be avoided by either malloc or something that i’m missing than it would be great.
You are not allocating an array of pointers, you are allocating an array of objects of type T with your code:
to allocate an array of pointers you need
I’m using a typedef so that the syntax is cleaner.