What's the fastest way to check if a slice points to static data

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 24 11:41:33 PDT 2017


On Saturday, 24 June 2017 at 18:05:55 UTC, ketmar wrote:
> Petar Kirov [ZombineDev] wrote:
>
>> ***
>> But in any case, the null-terminated string was just an 
>> example application.
>> I'm interested in a fast way to determine the "storage class" 
>> of the memory
>> a slice or a pointer point to. I'm expecting some magic along 
>> the lines of
>> checking the range of addresses that the rodata section 
>> resides in memory.
>> Similar to how some allocators or the GC know if they own a 
>> range of memory.
>> Any ideas on that?
>> ***
>
> the only query you can do is GC query (see `core.memory.CG` 
> namespace, `addrOf()` API, for example). it will tell you if 
> something was allocated with D GC or not.
>
> yet it is not guaranteed to be fast (althru it is usually "fast 
> enough").

I'm not interested in asking the GC specifically,
but I have looked at its implementation and I know
that it keeps such information around:
https://github.com/dlang/druntime/blob/v2.074.1/src/gc/impl/conservative/gc.d#L843

> i think this is all what you can get without resorting to ugly 
> platform-specific hacks (that will inevitably break ;-).

Oh, I should have mentioned that I don't expect anything but ugly 
platform-specific hacks possibly involving the object file format 
;)
Just enough of them to claim that the solution is somewhat 
cross-platform :D


More information about the Digitalmars-d-learn mailing list