08 setembro, 2021
# Exemplo 1 a <- b <- d <- 6 # identificador de memoria lobstr::obj_addr(a)
## [1] "0x9931c58"
lobstr::obj_addr(b)
## [1] "0x9931c58"
lobstr::obj_addr(d)
## [1] "0x9931c58"
# Vetor numerico de comprimento 3 w <- rnorm(3); w ## [1] -0.1918502 0.1235621 -1.0377259 # Acionando a funcao 'tracemem()' e imprimindo o id de memoria cat(tracemem(w), "\n") ## <00000000110D3AA8> # Vinculacao de outro nome e copia z <- w; z[2] <- 10 ## tracemem[0x00000000110d3aa8 -> 0x000000001117bc48]: eval eval withVisible withCallingHandlers handle timing_fn evaluate_call <Anonymous> evaluate in_dir eng_r block_exec call_block process_group.block process_group withCallingHandlers process_file <Anonymous> <Anonymous> # Desativando o rastreamento untracemem(w) # Modificando novamente o obj z z[1] <- 100; z ## [1] 100.000000 10.000000 -1.037726 # Identificador de memoria lobstr::obj_addr(z) ## [1] "0x1117bc48"
# Vetor w <- rnorm(3) # Inspecao .Internal(inspect(w)) ## @0x00000000060b2488 14 REALSXP g0c3 [REF(1)] (len=3, tl=0) -0.398,0.206,3.375 # Vinculacao de outro nome e copia z <- w # Inspecao .Internal(inspect(z)) ## @0x00000000060b2488 14 REALSXP g0c3 [REF(2)] (len=3, tl=0) -0.398,0.206,3.375 .Internal(inspect(w)) ## @0x00000000060b2488 14 REALSXP g0c3 [REF(2)] (len=3, tl=0) -0.398,0.206,3.375 z[2] <- 10 # Inspecao .Internal(inspect(z)) ## @0x00000000060b22a8 14 REALSXP g0c3 [REF(1)] (len=3, tl=0) -0.398,10,3.375 .Internal(inspect(w)) ## @0x00000000060b2488 14 REALSXP g0c3 [REF(1)] (len=3, tl=0) -0.398,0.206,3.375
z[2] <- 10 # Inspecao .Internal(inspect(z)) ## @0x00000000060b22a8 14 REALSXP g0c3 [REF(1)] (len=3, tl=0) -0.398,10,3.375 .Internal(inspect(w)) ## @0x00000000060b2488 14 REALSXP g0c3 [REF(1)] (len=3, tl=0) -0.398,0.206,3.375 # Modificando novamente o obj z z[1] <- 100; z ## [1] 100.00000 10.00000 3.37503 # Inspecao .Internal(inspect(z)) ## @0x00000000060b22a8 14 REALSXP g0c3 [REF(1)] (len=3, tl=0) 100,10,3.375 .Internal(inspect(w)) ## @0x00000000060b2488 14 REALSXP g0c3 [REF(1)] (len=3, tl=0) -0.398,0.206,3.375