小编lik*_*ern的帖子

通过显式调用构造函数(方法)来构造对象

课程定义:

#pragma once
#include <string>
#include <utility>

namespace impress_errors {

#define BUFSIZE 512

class Error {
public:
    Error(int number);
    Error(std::string message);
    Error(const char *message);
    bool IsSystemError();
    std::string GetErrorDescription();

private:
    std::pair <int, std::string> error;
    char stringerror[BUFSIZE]; // Buffer for string describing error
    bool syserror;
};

}  // namespace impres_errors
Run Code Online (Sandbox Code Playgroud)

我在文件posix_lib.cpp中有一段代码:

int pos_close(int fd)
{
    int ret;
    if ((ret = close(fd)) < 0) {
        char err_msg[4096];
        int err_code = errno;
        throw impress_errors::Error::Error(err_code); //Call constructor explicitly
    }
    return ret;
}
Run Code Online (Sandbox Code Playgroud)

在另一个文件fs_creation.cpp中:

int FSCreation::GenerateFS() …
Run Code Online (Sandbox Code Playgroud)

c++ constructor object

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

为什么CUDA共享内存初始化为零?

如此共享内存阵列默认值问题中所述,共享内存未初始化,即可以包含任何值.

#include <stdio.h>

#define BLOCK_SIZE 512

__global__ void scan(float *input, float *output, int len) {
    __shared__ int data[BLOCK_SIZE];

    // DEBUG
    if (threadIdx.x == 0 && blockIdx.x == 0)
    {
        printf("Block Number: %d\n", blockIdx.x);
        for (int i = 0; i < BLOCK_SIZE; ++i)
        {
            printf("DATA[%d] = %d\n", i, data[i]);
        }
    }

}

int main(int argc, char ** argv) {
    dim3 block(BLOCK_SIZE, 1, 1);
    dim3 grid(10, 1, 1);
    scan<<<grid,block>>>(NULL, NULL, NULL);
    cudaDeviceSynchronize();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是为什么在这段代码中它不是真的,而且我不断地将共享内存归零?

DATA[0] = 0
DATA[1] …
Run Code Online (Sandbox Code Playgroud)

c cuda gpu gpgpu nvidia

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

用xargs grep一些东西并找到

bash guru;)我正在尝试改进bash中的一些字符串,它在特定文件中grep特定关键字的匹配.它看起来像这样:

find /<path>/hp -iname '*.ppd' -print0 | xargs -0 grep "\*ModelName\:"
Run Code Online (Sandbox Code Playgroud)

这对我来说非常快!比这个快20倍:

find /<path>/hp -iname '*.ppd' -print0 | xargs -0 -I {} bash -c 'grep "\*ModelName\:" {}'
Run Code Online (Sandbox Code Playgroud)

但问题是在第一个脚本中我得到以下几行:

/<path>/hp/hp-laserjet_m9040_mfp-ps.ppd:*ModelName: "HP LaserJet M9040 M9050 MFP"
Run Code Online (Sandbox Code Playgroud)

但是期望的结果就是

*ModelName: "HP LaserJet M9040 M9050 MFP"  
Run Code Online (Sandbox Code Playgroud)

(如第二个脚本中所示).我怎样才能实现它?

PS:我正在使用find脚本的灵活性和未来的改进.

bash shell grep find

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

如何在类构造函数中调用泛型类型的构造函数

我想创建具有以下属性的Matrix2D类:

  1. 类应该是通用的
  2. 应该能够接受尽可能多的类型(理想情况下是所有类型)
  3. “默认”构造函数应使用默认类型值初始化所有单元格
  4. 正确处理大小写,当类型没有默认构造函数时(可能是默认参数解决了此问题)

我该怎么做?这是我的草图:

class Matrix2D<T> : Cloneable, Iterable<T> {
    private val array: Array<Array<T>>
    // Call default T() constructor if it exists
    // Have ability to pass another default value of type
    constructor(rows: Int, columns: Int, default: T = T()) {
        when {
            rows < 1 -> throw MatrixDimensionException("Number of rows should >= 1")
            columns < 1 -> throw MatrixDimensionException("Number of columns should be >= 1")
        }
        array = Array(rows, { Array(columns, { default }) }) …
Run Code Online (Sandbox Code Playgroud)

generics kotlin

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

标签 统计

bash ×1

c ×1

c++ ×1

constructor ×1

cuda ×1

find ×1

generics ×1

gpgpu ×1

gpu ×1

grep ×1

kotlin ×1

nvidia ×1

object ×1

shell ×1