Pass pointer by reference and memory saving