extracted array functions and improved memory use

Signed-off-by: Gerald <gera2ld@163.com>