separate out PortalMemory code so I can include generated types safely. also add callback registrationto some of the statistics reporting