SetMemory and SetMemoryFlags implementation