我有记忆不一致吗? Macos [英] Do I have a memory inconcistency? Macos

查看:138
本文介绍了我有记忆不一致吗? Macos的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用活动监视器,但是这产生严重的不一致。我有一个运行程序,建立和存储一个60 x 100,000的10维GSL向量的双精度数组,另一个6 x 60阵列的16,807维GSL向量。

I currently use Activity monitor, however this yields a serious inconsistency. I have a running program that builds and stores a 60 x 100,000 array of 10 dimensional GSL vectors in double precision, and another 6 x 60 array of 16,807 dimensional GSL vectors.

GSL向量本质上是一个双精度数据和一个指针的数组,所以我使用GSL库认为它应该准确地测量他们的使用只是双精度组件。

GSL vectors are essentially an array of double precision data and a pointer, so I think it should be accurate to measure their usage in terms of just the double precision components.

现在,根据我的计算,我应该存储大约500 MB的数据(8bytes每双)。但是,我的Macos活动监视器告诉我,我存储1.4 GB的真实内存。现在,这可能是一个非常不准确的方法来衡量内存使用,但它不是不准确预测我的机器将从使用RAM切换到使用交换,并变得非常缓慢!例如,当我将第一个数组大小增加到60 x 400k时,内存不足,一切都停止了。

Now, by my calculations, I should be storing around 500 MB of data (8bytes per double). However, my Macos Activity monitor tells me I'm storing 1.4 GB of "real" memory. Now, this may be a very inaccurate method to measure memory usage, but it's not inaccurate at predicting when my machine will switch from using RAM to using swaps, and become very slow! When I increase the first array size to 60 x 400k, for example, I run out of memory and everything stops dead.

这是我的数学错误,是否有什么问题,我的电脑估计它存储多少数据的方式?

So is it that my math is wrong, or is there something going wrong with the way my computer is estimating how much data it's storing?

编辑:或者是关于我存储指针数据的方式混淆分配器对大量过度补偿存储需求?

Or is it something about the way I'm storing pointer based data that's confusing the allocator into massively overcompensating the storage need?

编辑2:数据存储在 stl :: vector< stl :: vector< gsl :: gsl_vector *> > 结构。我读了Eigen不使用动态内存分配:这可以导致内存管理的实质性改进吗?

EDIT 2: The data is stored in stl::vector< stl::vector<gsl::gsl_vector * > > structures. I read that Eigen does not use dynamical memory allocation: could this lead to substantial improvement in the memory management?

推荐答案

600,000 std :: vectors 。这是很大的开销。每个向量不是简单的数组 - 有指针,大小,容量,对齐等开销。我怀疑你在堆上分配你的GSL向量?

You are creating 600,000 std::vectors. That's a lot of overhead. Each of those vectors isn't simply an array - there is an overhead of pointer, size, capacity, alignment, etc. Plus I suspect you allocate your GSL vectors on the heap?

Eigen可以部分解决您的问题,因为它有一个Matrix类的静态专业化。但是,你应该真正考虑使用一个合适的3d连续存储数组/张量对象。

Eigen may partially solve your problems as it has a static specialization of Matrix class. However, you should be really thinking of using a proper 3d contigous storage array/tensor object.

这篇关于我有记忆不一致吗? Macos的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆