Skip to content

Array pointer ignores offset #43056

@baumgold

Description

@baumgold

When getting a pointer from an array (via the pointer function) the resulting memory address describes the beginning of the array, but ignores the array's offset. AFAIK the offset is used to efficiently "soft" delete objects at the beginning of the array (here). If this is in-fact the case, then the offset should be taken into account when returning the memory address of the start of the array (here). Specifically, instead of having jl_array_ptr return a->data we might want to return a->data + a->offset.

A reproducible example follows below. Note that the memory-address doesn't change even after calling popfirst!(). I expect that the memory-address would increment after the call to popfirst!().

julia> v = [1,2]
2-element Vector{Int64}:
 1
 2

julia> pointer(v)
Ptr{Int64} @0x00007fffdef09d30

julia> popfirst!(v)
1

julia> pointer(v)
Ptr{Int64} @0x00007fffdef09d30

julia> versioninfo()
Julia Version 1.6.3
Commit ae8452a9e0 (2021-09-23 17:34 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) Gold 6136 CPU @ 3.00GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake-avx512)
Environment:
  JULIA_NUM_THREADS = 4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorgood first issueIndicates a good issue for first-time contributors to Julia

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions