Skip to content

Commit

Permalink
#156: footprinting: support vector of non-serializable elements
Browse files Browse the repository at this point in the history
  • Loading branch information
cz4rs committed Nov 19, 2020
1 parent 56f3104 commit 98a67ab
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/checkpoint/container/vector_serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ void serialize(Serializer& s, std::vector<bool, VectorAllocator>& vec) {
}
}

template <
typename SerializerT,
typename T,
typename VectorAllocator,
typename = std::enable_if_t<
std::is_same< // is_footprintable
size_t,
decltype(checkpoint::getMemoryFootprint(std::declval<T>()))
>::value
>
>
void serialize(SerializerT& s, std::vector<T, VectorAllocator>& vec) {
s.countBytes(vec);
s.addBytes(vec.capacity() * sizeof(T));
}

} /* end namespace checkpoint */

#endif /*INCLUDED_CHECKPOINT_CONTAINER_VECTOR_SERIALIZE_H*/
13 changes: 13 additions & 0 deletions tests/unit/test_footprinter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -586,4 +586,17 @@ TEST_F(TestFootprinter, test_ompi) {
}
}

struct TestNoSerialize {
double d;
int i;
};

TEST_F(TestFootprinter, test_no_serialize) {
std::vector<TestNoSerialize> v(7);

EXPECT_EQ(
checkpoint::getMemoryFootprint(v),
sizeof(v) + v.capacity() * sizeof(TestNoSerialize)
);
}
}}} // end namespace checkpoint::tests::unit

0 comments on commit 98a67ab

Please sign in to comment.