In this tutorial, we are introducing one new package- lobstr that contains functions for memory management and in here we are dealing with three of its functions.
- obj_size that is going to return size in bytes for variable provided as argument.
- mem_used is going to return memory used by the session in bytes.
- obj_addr is going to return hexadecimal representation of memory address of variable provided as argument.
First thing that you must know about variables in regards of memory is that whenever value of some variable is changed, R creates new address for that variable. If we provide one variable as value for another variable like in case
a <- 10
b <- a
not only that a and b will be of equal value but of equal address too. Only way to avoid that is to provide value as part of collection like
a <- c( b)
now a will hold all of elements of b but not its address; a and b will be two completely different variables. Same stands for function arguments. If you provide a to a function as an argument, that argument is going to be treated as passed by reference; else if you provide c( a), in this case it will be treated as passed by value.
Video tutorial link below.
No comments:
Post a Comment