update shared memory access logic with some meta programming