dynamic mem allocater
faster impl