小编Ada*_*hon的帖子

新char [n]和new(char [n])之间的差异

有什么区别new char[n]new (char[n])

我在生成的代码中有第二种情况,g ++(4.8.0)给了我

ISO C++ does not support variable-length array types [-Wvla]
Run Code Online (Sandbox Code Playgroud)

这让我想到这两者是否相同.

  1. new char[n]意思是"分配n类型的对象char.
  2. 是否new (char[n])意味着"分配1个类型的对象array of n chars"?
  3. 删除第一个很清楚.
  4. 我应该用delete或删除第二个delete[]
  5. 我应该注意哪些其他差异?
  6. 我可以安全地删除括号并将第二种情况转换为第一种情况,当软件的其他部分期望第二种情况时?

代码由第三方软件生成(并由软件的其他部分使用),因此我不能只是"使用向量".

这是最小的例子:

int main (void)
{
    int n(10);
    int *arr = new (int[n]); // removing parentheses fixes warning
    *arr = 0; // no "unused variable" warning
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ memory-management

23
推荐指数
2
解决办法
1470
查看次数

64位unix时间戳转换

是否有针对32位系统的64位unix时间戳转换的C++实现?我需要转换struct tm为64位整数,反之亦然,包括闰年,时区,UTC.还需要它可移植,至少对于GNU/Linux和Windows.

c++ linux windows time 64-bit

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

opencv warpPerspective参数计数

在我的脚本中,我有以下代码:

src = numpy.array(cornersSheet, numpy.float32)
dst = numpy.array(cornersDesired, numpy.float32)
transform = cv2.getPerspectiveTransform(src,dst)
finished = cv2.warpPerspective(img, transform, img.shape)
Run Code Online (Sandbox Code Playgroud)

Python说:

Traceback (most recent call last):
File "./script.py", line 138, in <module>
    finished = cv2.warpPerspective(img, transform, img.shape)
TypeError: function takes exactly 2 arguments (3 given)
Run Code Online (Sandbox Code Playgroud)

但根据文件:

    Python: cv2.warpPerspective(src, M, dsize[, dst[, flags[, borderMode[, borderValue]]]]) ? dst
Run Code Online (Sandbox Code Playgroud)

三个参数都可以.我有同样的问题cv2.warpAffine.

python opencv numpy

9
推荐指数
2
解决办法
3400
查看次数

jenkins 在工作终止后将 @(at 符号)添加到工作区名称

我使用 jenkins 流水线项目来构建我的基于 OpenEmbedded 的项目。我的声明性管道的节点包含

customWorkspace "/data/jenkins/oe/"
Run Code Online (Sandbox Code Playgroud)

Jenkins 实际上构建了一个更深的目录,在

/data/jenkins/oe/project-name/
Run Code Online (Sandbox Code Playgroud)

这不是问题。但是在我在开发过程中杀死了一项工作之后,jenkins 现在在路径中添加了 at 符号,例如

/data/jenkins/oe/project-name@2/
Run Code Online (Sandbox Code Playgroud)

这会杀死 OE。

...@2如果我删除一切从目录甚至恢复/data/jenkins/oe/。我也尝试基于此错误启用并发构建,但这些都不起作用。

是什么导致了这种行为以及如何避免它?要么禁用 at 符号使用,要么禁用子目录使用?

jenkins jenkins-pipeline

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

如何在Python中显示和更新位图FAST?

我有一个设备,我从中读取图像.每个图像都是一行8b灰度像素的数组.如何将图像序列显示为视频?

像这样的东西:

while !terminated:
    image = readImage(...)
    widget.updateImage(image, width, height)
Run Code Online (Sandbox Code Playgroud)

产品规格:

  • 必须使用PyQt实现

python user-interface image

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

平均执行时间

有没有什么好的GNU方法如何测量某些命令行程序的平均(最坏情况,最佳情况)执行时间?我有图像过滤器,未指定数量的图片,在bash中使用for循环过滤它们.到目前为止,我正在使用时间,但我找不到如何获得一些统计数据的方法.

c bash profiling

5
推荐指数
2
解决办法
2086
查看次数

使删除的指针无效?

template<typename T>
someclass<T>& operator=(const someclass<T>& other)
{
    typename std::vector<T *>::const_iterator rhs;
    typename std::vector<T *>::iterator lhs;

    //identity test
    //this->data is std::vector<T *>

    for(lhs = this->data.begin(); lhs != this->data.end(); lhs++)
    {
        delete *lhs;
    }

    this->data.clear(); // this is what I forgot

    this->data.reserve(other.data.size());
    for (rhs = other.data.begin(); rhs != other.data.end(); rhs++)
    {
        if (NULL == *rhs)
        {
            this->data.push_back(NULL);
        }
        else
        {
            this->data.push_back(new T(**rhs));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

正如您在评论中看到的那样,我忘了清除数组中的旧指针.当我第二次调用赋值运算符时,我得到glibc错误抱怨双重释放.提供的唯一信息是删除的地址.

这让我想到如何处理这类已删除的指针 - 当你不想再删除它们时,当你这样做时,肯定是一个错误.您不能将它们设置为NULL,因为另一个删除是正确的.您不希望保留该值,因为可以将内存位置分配给新创建的对象.

什么是适合调试是一些价值,如无效,对分配给这些指针说:"调用删除这个指针是一个错误",而不是NULL,它说"援引这个指针删除什么都不做".有这样的事吗?

c++ pointers memory-management invalidation

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