Update globalmem.c

some improvement on initial version