What is the total amount of memory necessary (in Bytes) to create a 4 x 3 x 3 array of doubles dynamically?

I know the answer is 356 but simply do not understand where the extra bytes are coming from. A lille help please?

有帮助吗?

解决方案

So as @user4815162342 says, you need at least 288 bytes for doubles but he/she didn't say nothing about extra 68 bytes for 17 pointers. This makes 356 bytes. 32 bit integers assumed as pointers.
1. You need 1 pointer to the entire array.
2. Then 4 pointers on the second dimension.
3. Finally 12 pointers on the third dimension.

其他提示

The answer will vary from platform to platform, and can also depend on the number and nature of previous allocation. Thus the answer you "know" is almost certainly incorrect in some cases.

The answer guaranteed to be correct is that the required amount of memory is "at least 4*3*3*sizeof(double) bytes", which is 288 on most modern platforms.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top