我正在尝试将大量数据写入我的SSD(固态硬盘).大量的我的意思是80GB.
我浏览网页寻求解决方案,但我想出的最好的是:
#include <fstream>
const unsigned long long size = 64ULL*1024ULL*1024ULL;
unsigned long long a[size];
int main()
{
std::fstream myfile;
myfile = std::fstream("file.binary", std::ios::out | std::ios::binary);
//Here would be some error handling
for(int i = 0; i < 32; ++i){
//Some calculations to fill a[]
myfile.write((char*)&a,size*sizeof(unsigned long long));
}
myfile.close();
}
Run Code Online (Sandbox Code Playgroud)
使用Visual Studio 2010进行编译并完全优化并在Windows7下运行,此程序最大可达20MB/s.让我感到困扰的是,Windows可以将文件从其他SSD复制到此SSD,速度介于150MB/s和200MB/s之间.所以至少快7倍.这就是为什么我认为我应该能够更快.
我有什么想法可以加快我的写作速度?
我正在处理IfcFace.我给了一个带孔的简单多边形,我需要将它转换成多个没有孔的简单多边形,以便CAD进一步处理它.一点点演示ilustration:
我最好的方法是做一个约束的delaunay三角剖分并将三角形重新加入更大的多边形.像这样:
但是由于浮点精度和算法不稳定性,delaunay三角剖分甚至更多的约束部分往往因难以输入而失败.我的输入有时会生成高度为1e-8且基本长度为1的三角形.
是否有更好的更强大的算法来实现这种转换?
我在C++类中有以下代码:
class Features
{
#define Feature_Size_A 12345
#define Feature_Size_B 45678
#define Feature_Size_C 78901
//#define Feature_Size_D 14725
const int Feature_Sum = 0
#ifdef Feature_Size_A
+ Feature_Size_A
#endif
#ifdef Feature_Size_B
+ Feature_Size_B
#endif
#ifdef Feature_Size_C
+ Feature_Size_C
#endif
#ifdef Feature_Size_D
+ Feature_Size_D
#endif
;
#ifdef Feature_Size_A
static float Feature_A[Feature_Size_A];
#endif
#ifdef Feature_Size_B
static float Feature_B[Feature_Size_B];
#endif
#ifdef Feature_Size_C
static float Feature_C[Feature_Size_C];
#endif
#ifdef Feature_Size_D
static float Feature_D[Feature_Size_D];
#endif
};
Run Code Online (Sandbox Code Playgroud)
我过去常常注释掉第4行的功能来编译和运行不同的测试.但是现在我想将类作为模板,因此我可以在同一个程序中实例化具有不同功能的多个版本.
我在考虑这样的事情:
template <bool Feature_A, bool Feature_B, bool Feature_C, bool Feature_D>
class Features …Run Code Online (Sandbox Code Playgroud) 我想出了一个名为TinyVector的小班.现在我正在尝试使用std :: inner_product.但我不能让它工作,我不明白为什么这不起作用.我正在使用Visual Studio 2012.
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
template<class T, int N>
class TinyVector {
public:
TinyVector() { data = vector<T>(N, 0); }
explicit TinyVector(const T initVal) { data = vector<T>(N, initVal); }
~TinyVector() { data.clear(); }
inline T& operator[](int i) { return data[i]; }
inline T operator[](int i) const { return data[i]; }
inline vector<T>::const_iterator begin() const { return data.begin(); } //Line 15
inline vector<T>::const_iterator end() const { return data.end(); } //Line 16 …Run Code Online (Sandbox Code Playgroud)