M
Modular6mo ago
benny

Determine Pointer Location

Hey everyone :) Got stuck on an issue and was wondering if anyone knew how to implement a kind of function to check if a pointer is allocated on the stack or the heap, i.e.
fn is_stack[T: DType](ptr: DTypePointer[T]) -> Bool:
...
fn is_stack[T: DType](ptr: DTypePointer[T]) -> Bool:
...
That returns true for a pointer that was created with stack_allocate[T], but false for DTypePointer[T].alloc
1 Reply
Darkmatter
Darkmatter5mo ago
For single-threaded, you can check which memory mapping contains the address of a stack value. For MT, it's a bit more messy unless you know that the pointer is either from the local stack or heap allocated. Did you manage to figure this out or do you want me to dig up some old C/Rust (Can't remember which) code I have that does this?
Want results from more Discord servers?
Add your server