Common functions for memory and string length.