Since C++11, you can check the size during compilation:
static_assert (sizeof(mystruct) == 1024, "Size is not correct");
Pre-c++11 compilers, Boost has a workaround:
BOOST_STATIC_ASSERT_MSG(sizeof(mystruct) == 1024, "Size is not correct");
See the documentation.