recode memdev.c by moon