I think you should use vector_size here .. the length is how many value_type elements we have which is not always equal to the size (i.e. number of bytes)