dont forget to update write_cnt when reading from fd or marshal