ugtrain: improve and move the dynmem allocation to new files

src/memmgmt.cpp
src/memmgmt.h

Functionality is basically the same. Just renaming and negating
checks to reduce indention.