Add unit test for memory layout based off the Kenton's layout-test.c++ and whole slew of fixes to get the test to pass