changed allocate function to accept count of typed elements rather than size in bytes.