如何通过程序估计cache大小?字节里数据显示出来时是如何表现在内存里的
通过访问数组元素等①些简单的方式估计cache大小
更靠谱的方式是:
可以参考openblas:
或者我们直接点:
#include #include #include #include #include std::string exec(const char* cmd) { char buffer[①②⑧]; std::string result = \"\"; std::shared_ptr pipe(popen(cmd, \"r\"), pclose); if (!pipe) throw std::runtime_error(\"popen() failed!\"); while (!feof(pipe.get())) { if (fgets(buffer, ①②⑧ · pipe.get()) != NULL) result += buffer; } return result;}int main() { std::string cacheInfo;#if defined(__OSX__) || defined(__APPLE__) cacheInfo = exec(\"sysctl -a | grep -i hw.cache\");#else cacheInfo = exec(\"getconf -a | grep -i cache\");#endif std::cout sysctl -a | grep -i hw.cache
hw.cachelinesize: ⑥④hw.cachesize: ①⑦①⑦⑨⑧⑥⑨①⑧④③②⑦⑥⑧ ②⑥②①④④ ⑥②⑨①④⑤⑥ ⓪ ⓪ ⓪ ⓪ ⓪ ⓪hw.cacheconfig: ⑧ ② ② ⑧ ⓪ ⓪ ⓪ ⓪ ⓪ ⓪
②. Linux
~> getconf -a | grep -i cache
LEVEL①_ICACHE_SIZE ③②⑦⑥⑧LEVEL①_ICACHE_ASSOC ⑧LEVEL①_ICACHE_LINESIZE ⑥④LEVEL①_DCACHE_SIZE ③②⑦⑥⑧LEVEL①_DCACHE_ASSOC ⑧LEVEL①_DCACHE_LINESIZE ⑥④LEVEL②_CACHE_SIZE ②⑥②①④④LEVEL②_CACHE_ASSOC ⑧LEVEL②_CACHE_LINESIZE ⑥④LEVEL③_CACHE_SIZE ②⓪⑨⑦①⑤②LEVEL③_CACHE_ASSOC ⑧LEVEL③_CACHE_LINESIZE ⑥④LEVEL④_CACHE_SIZE ⓪LEVEL④_CACHE_ASSOC ⓪LEVEL④_CACHE_LINESIZE ⓪\", \"extras\": \"\", \"created_time\": ①④⑧①⑤⓪⑤③②⓪ · \"type\": \"answer
这不就是我在这个系列里详细解释的嘛…而且这个问题用了两篇文章
我还以为真没人想看呢(((o(*゚▽゚*)o)))
如何解释内存里的数据是程序员的自由,你用%d输出就是数字,用%s输出就是字符串
① · 区分内存中的字节和显示器中的字符。
两者并非①①对应,因为显示器的显示是廉价的,并且要服务于“人”这个使用者的习惯。
② · 存储方式可以有不同方式,比如①⓪⓪可以用③个字节存储。但是那通常是“字符串”。
- 5星
- 4星
- 3星
- 2星
- 1星
- 暂无评论信息
