unsafe_store!

unsafe_store!(p::Ptr{T},x,i::Integer)

Store a value of type T to the address of the ith element (1-indexed) starting at p. This is equivalent to the C expression p[i-1] = x.

The unsafe prefix on this function indicates that no validation is performed on the pointer p to ensure that it is valid. Incorrect usage may corrupt or segfault your program, in the same manner as C.

Examples

"""
unsafe_store!(p::Ptr{T}, x, i::Integer)

Store a value of type `T` to the address of the ith element (1-indexed) starting at `p`.
This is equivalent to the C expression `p[i-1] = x`.

The `unsafe` prefix on this function indicates that no validation is performed on the pointer `p` to ensure that it is valid.
Incorrect usage may corrupt or segfault your program, in the same manner as C.
"""

# Example 1: Store an integer value at the given pointer address
julia> ptr = C_NULL
Ptr{Nothing} @0x00000000ffffffff

julia> unsafe_store!(ptr, 42, 1)

# Example 2: Store a string value at the given pointer address
julia> str = "Hello, World!"
julia> cstr = Cstring(str)
Ptr{UInt8} @0x000000010d4c9c80

julia> unsafe_store!(cstr, 'J', 8)

Note: The unsafe_store! function should be used with caution as it bypasses the usual safety checks performed by Julia. It is primarily used when interacting with external libraries or low-level operations where manual memory management is required. Incorrect usage of unsafe_store! can lead to memory corruption or program crashes.

See Also

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: