Home > Net >  Check if an arrow Array created from an atomic vector makes a copy of that vector
Check if an arrow Array created from an atomic vector makes a copy of that vector

Time:12-23

I am trying to check if creating an arrow Array from an r object creates a copy or not. I create an array and then create an atomic vector back from that array but the memory adress doesn't seem to be the same... Is there something I am doing wrong?

> library(arrow)
> v = c(1L,2L,3L)
> a = arrow::Array$create(v)
> 
> .Internal(inspect(v))
@0x00000248ddac1f38 13 INTSXP g0c2 [REF(5)] (len=3, tl=0) 1,2,3
> .Internal(inspect(v[1]))
@0x00000248d5bc3dd0 13 INTSXP g0c1 [] (len=1, tl=0) 1
> 
> d = a$as_vector()
> .Internal(inspect(d))
@0x00000248da541230 13 INTSXP g0c0 [REF(65535)] arrow::ChunkedArray<0x00000248dac3e2b0, int32, 1 chunks, 0 nulls> len=3
> .Internal(inspect(d[1]))
@0x00000248d5bc3fc8 13 INTSXP g0c1 [] (len=1, tl=0) 1

CodePudding user response:

I am not quite sure what your goal is? If you want to see if converting from vector > arrow creates a a copy you have your answer: yes it does and that's why the memory addresses are different.

Converting the R vector into an arrow array converts it to the arrow memory layout via the libarrow C library which lives in memory outside of R. You can confirm this by saving and loading an arrow object:

r$> save(a, file = "test")

r$> load("test")

r$> a
Array
Error: Invalid <Array>, external pointer to null
  • Related