문제

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