Pointers are memory addresses. They have difference uses. One of their use is to pass data objects to functions by memory address, instead of creating another copy of the object in memory. It can not only save memory, but also provide some speed advantage. In the following example, I shall create a vector of 100 million observation, and show the speed advantage of pointers over passing the vector by name to a function.


mata
mata clear
timer_clear()
a = range(0, 100000000, .25)
b = &a
timer_on(1)
real scalar findmean(a) {
    return(mean(a))
}
findmean(a)
timer_off(1)

timer_on(2)
real scalar findmeanp(pointer scalar b) {
    return(mean(*b))
}
findmeanp(b)
timer_off(2)
timer()

--------------------------------------------------------------
timer report
  1.         11 /        1 =    10.982
  2.       6.35 /        1 =     6.348
---------------------------------------------------------------


end