The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

314192 (3) [Avatar] Offline
A reference object, compared to a value type, has extra memory overhead due to the pointer size required to access the memory location of the object allocated in the heap. This pointer size is 8 bytes in 32-bit processes and 6 bytes in 64-bit processes.

Is that right?
Riccardo (3) [Avatar] Offline
Good catch, this is a typo. I am actually reviewing the initial chapters of the book and I am fixing this.

To answer your question, the size of the memory address depends entirely on the architecture of the CPU and the compiler implementation. In general, for comparison purpose, the size of a pointer in 32 bit machine is 4 bytes (32 bi ) and 8 bytes (64 bit) in a 64 bit machines.

This type will be fixed in the next MEAP release!
Thank you
314192 (3) [Avatar] Offline
Many thanks for your answer. What you say is correct, but I wonder if it would help to go into more detail.

The difference in storage cost between i) a struct containing one pair of floats, and ii) one pointer to an object can amount to a few bytes of stack space per *thread*.

On the other hand, there is an absolutely massive difference in the amount of garbage generated (as noted in table 4.1). An object in .net will conventionally store i) a pointer to the sync block, ii) a pointer to the RTTI information, and iii) its content (i.e. the two floats). So we have contrast between i) no garbage at all (because the pair of floats can live on the stack) and ii) every pixel needing enough heap space for two pointers and two floats (which turns into garbage almost immediately).

I wonder if the original intent was to say 8/16 as opposed to 8/6 (what the quoted paragraph says now). If so, I think it should instead say 16/24 because the two floats become garbage in the same way (and at the same cost) as the two extra pointers. Either way, correcting the sizes to 4/8 would result in an accurate sentence but one that merely adds information to something that is at best misleading. Namely, the following sentence that refers to a completely irrelevant amount of storage on the stack: "has extra memory overhead due to the pointer size required to access the memory location of the object allocated in the heap". The space is trivial because we need one extra pointer per thread, and it is in any case an alternative to storing two floats which might be exactly the same size.

I don't know how to easily fix the paragraph so it would give correct information without going off on a tangent. That's probably why I don't write books smilie

Without wishing to nitpick, this sentence is untrue in general "...a value type is not allocated in the heap but rather in the stack...". Maybe it should say *local* variables that are values can be stored on the stack.
Riccardo Terrell (31) [Avatar] Offline
I will add a Sidebar to provide further details