Address of a class object

H. S. Teoh hsteoh at qfbox.info
Thu Jan 5 17:23:39 UTC 2023


On Thu, Jan 05, 2023 at 06:32:47AM +0000, areYouSureAboutThat via Digitalmars-d-learn wrote:
[...]
> Second, to be sure your getting the correct results, it would be nice
> if there was a 'category of type' in std.traits for:
> 
> isAllocatedOnStack
> isAllocatedOnHeap
> 
> As it is, your just guessing (although the addresses printed will
> clear this up for you anyway I guess).

In general, it's not possible to determine whether an arbitrary
reference is pointing to the stack or the heap, because it could have
come from anywhere.  You can only determine this if you are privy to the
internal implementation details of the allocator or code that created
the reference (GC, other allocator, or whatever took an address of a
stack-allocated object), or the platform-specific details of your
runtime environment (range of stack addresses).


> Also, I cannot read hex,
[...]

IMNSHO, anyone who claims to be a programmer should at least know that
much.  As Knuth once said,

	People who are more than casually interested in computers should
	have at least some idea of what the underlying hardware is like.
	Otherwise the programs they write will be pretty weird.
	-- D. Knuth


T

-- 
"Real programmers can write assembly code in any language. :-)" -- Larry Wall


More information about the Digitalmars-d-learn mailing list