Hello, in the following code I am confused about what is going on in line 41:
pd2 = new (buffer + N * sizeof(double)) double[N];
I cannot understand what sizeof is supposed to be calculating.
sizeof() is a function that returns the amount of memory used by its input. In this case, the code is asking for the amount of memory a standard double requires. This function is important for direct memory allocation, a key feature of C/C++. For example: In the line of code it's being used in, it seems that this code is allocating memory for a buffer to store double values before being output to cout.
It seems that this code is allocating memory for a buffer to store double values before being output to cout.
No. Line 41 is a placement new. This does not actually allocate any memory. The expression in the () calculates an address based on the address of buffer at line 7 and adds the size of N doubles to the base address.
No. Line 41 is a placement new. This does not actually allocate any memory. The expression in the () calculates an address based on the address of buffer at line 7 and adds the size of N doubles to the base address.
Oh my mistake. Pointer arithmetic is even more esoteric to me.