resize before read

This commit is contained in:
froejdh_e 2025-04-11 13:38:33 +02:00
parent 92f5421481
commit e71569b15e
2 changed files with 3 additions and 2 deletions

View File

@ -229,6 +229,7 @@ ClusterFile<ClusterType, Enable>::read_clusters_without_cut(size_t n_clusters) {
} }
ClusterVector<ClusterType> clusters(n_clusters); ClusterVector<ClusterType> clusters(n_clusters);
clusters.resize(n_clusters);
int32_t iframe = 0; // frame number needs to be 4 bytes! int32_t iframe = 0; // frame number needs to be 4 bytes!
size_t nph_read = 0; size_t nph_read = 0;
@ -283,7 +284,7 @@ template <typename ClusterType, typename Enable>
ClusterVector<ClusterType> ClusterVector<ClusterType>
ClusterFile<ClusterType, Enable>::read_clusters_with_cut(size_t n_clusters) { ClusterFile<ClusterType, Enable>::read_clusters_with_cut(size_t n_clusters) {
ClusterVector<ClusterType> clusters; ClusterVector<ClusterType> clusters;
clusters.reserve(n_clusters); clusters.resize(n_clusters);
// if there are photons left from previous frame read them first // if there are photons left from previous frame read them first
if (m_num_left) { if (m_num_left) {

View File

@ -299,7 +299,7 @@ class ClusterVector<Cluster<T, ClusterSizeX, ClusterSizeY, CoordType>> {
*/ */
ClusterVector(size_t capacity = 1024, uint64_t frame_number = 0) ClusterVector(size_t capacity = 1024, uint64_t frame_number = 0)
: m_frame_number(frame_number) { : m_frame_number(frame_number) {
m_data.resize(capacity); m_data.reserve(capacity);
} }
// Move constructor // Move constructor