Is it safe to do this? The memset() part is what I'm worried about.
Yes, it's safe, in the sense that this won't cause any undefined behaviour (buffer overflows, uninitialised values, etc.).
However, it won't necessarily set your values to zero. memset
sets the bits to 0, but this isn't necessarily the same as setting e.g. a float
to a value of 0
(although in practice, it will be fine on most normal platforms).