Address of a class object

Steven Schveighoffer schveiguy at gmail.com
Wed Jan 4 20:02:35 UTC 2023


On 1/4/23 2:27 PM, Ali Çehreli wrote:
> On 1/4/23 10:48, H. S. Teoh wrote:
> 
>  > Allocations are not necessarily consecutive; the GC may have its own
>  > strategy of allocation that doesn't follow a linear sequence.
> 
> That was one of my guesses. So, I put the objects into a 2-length static 
> array but the difference was still 0x20. (?)

Are you putting the class *references* in a 2-length static array? 
That's just going to be 2 pointers in an array, and won't affect where 
they are allocated on the heap.

>  > Furthermore, GC-allocated blocks may be larger than the request size
>  > because there may be some extra management information stored in the
>  > block (but outside the pointer range returned).
> 
> Good point. I think the minimum size of a dynamically allocated memory 
> of the current GC implementation is 32 bytes.

It is 16 bytes, but there are no 24-byte bins. Here are the bin sizes:

https://github.com/dlang/dmd/blob/4dc7259a89950b0a0feda05b8c35e52cadd00c95/druntime/src/core/internal/gc/impl/conservative/gc.d#L1402-L1424

And of course, this could change again.

Basically, follow H. S. Teoh's advice, stop worrying about the addresses 
given out by the GC, it's not important.

-Steve


More information about the Digitalmars-d-learn mailing list