小编Lig*_*XXV的帖子

c ++读取文件太慢了

我试图阅读~36KB,完成这个循环需要大约20秒:

ifstream input_file;

input_file.open("text.txt");
if( !(input_file.is_open()) )
{
    cout<<"File not found";
    exit(1);
}

std::string line;
stringstream line_stream;   //to use << operator to get words from lines

int lineNum=1;

while( getline(input_file,line) )   //Read file line by line until file ends
{
    line_stream.clear();    //clear stream
    line_stream << line;    //read line
    while(line_stream >> word)  //Read the line word by word until the line ends
    {
        //insert word into a linked list...
    }
    lineNum++;
}
input_file.close();
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激.

c++ stream

3
推荐指数
1
解决办法
980
查看次数

Nvidia CUDA Profiler 的时间线包含很多大的缺口

我正在尝试使用 Nivida Profiler 分析我的代码,但我在时间线中出现了奇怪的差距,如下所示:

时间线差距

注意:间隙边缘的两个内核都是 CudaMemCpyAsync(主机到设备)

我在 Ubuntu 14.04 上运行最新版本的 CUDA、8.0.61 和最新的 Nvidia 显示驱动程序。

Intel 集成显卡用于显示器而不是 Nvidia。因此,Nvidia 显卡只运行代码,而不运行其他任何东西。

我也启用了 CPU Profiling 来检查这些差距,但没有显示任何内容!

已启用 CPU 分析

此外,没有启用调试选项(-G 或 -g),这是一个“发布版本”

没有启用调试选项

我的笔记本电脑规格:

  • 英特尔酷睿 i7 4720HQ
  • 英伟达 GTX 960m
  • 16GB DDR3 内存
  • 1 TB 硬盘

有没有办法追踪这些空时隙中发生的事情?

谢谢,

profile timeline cuda nvidia

3
推荐指数
1
解决办法
332
查看次数

具有默认参数的C ++基类构造函数

我写了这个小程序来测试我的理解。我很难理解的是构造函数没有被继承,但是类B能够调用类A的构造函数!

#include <iostream>
using namespace std;

class A {
public:
    A(int x = 2) {          //Constructor A
        num = x;
    }
    int getNum() {
        return num;
    }

protected:
    int num;
};

class B: public A {         //Constructor B
public:
    B() {
        A(5);
    }
};

int main() {

    A a(3);                     //create obj a with num = 3
    B b;                        //create obj b
    cout << a.getNum() << endl;
    cout << b.getNum() << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出为:

3
2
Run Code Online (Sandbox Code Playgroud)

构造函数A的调用到底做了什么?它没有使用传递的参数来初始化对象b的编号!

此外,如果我从类A的构造函数中删除默认值,则会出现编译错误:

no …
Run Code Online (Sandbox Code Playgroud)

c++ constructor derived-class default-parameters

1
推荐指数
1
解决办法
1714
查看次数