-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Document how to cast / recast / change type of pointer inside Ptr docs #58641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
c42242d
389aa6d
6c42551
3ffd9c3
96b09df
7fde5bd
436121d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,16 @@ | |
""" | ||
Ptr{T} | ||
|
||
A memory address referring to data of type `T`. However, there is no guarantee that the | ||
A memory address referring to data of type `T`. However, there is no guarantee that the | ||
memory is actually valid, or that it actually represents data of the specified type. | ||
Some operations like [`unsafe_load`](@ref) are only supported when T is an [`isbitstype`](@ref) | ||
while [`unsafe_wrap`](@ref) also supports abstract types. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not meant as an alternative to pointers. |
||
Use [`reinterpret`](@ref) to get a pointer with the same address but a different type. | ||
freemin7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
!!! warning | ||
When T is a [`Union`](@ref) type, the pointer does not contain the necessary information | ||
to reconstruct what elements in the array had which type. Such pointers can't be use to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pointers are not just for arrays. For example, you can get a pointer to a field in an mutable struct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/immutable/mutable I assume There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "what data type it pointed to." would that be better? |
||
retrieve any Julia objects. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's still possible to retrieve an object, you just have to know what type you're looking for. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well then you would manually de-unionize the pointer and it no longer the "same" pointer. I will think of a different phrasing. |
||
""" | ||
Ptr | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.