小编Cha*_*les的帖子

为什么这个版本的strcmp更慢?

我一直在尝试strcmp在某些条件下提高性能.但是,遗憾的是,我甚至无法实现普通的vanilla strcmp以及库实现.

我看到了一个类似的问题,但答案说差异来自编译器优化掉字符串文字的比较.我的测试不使用字符串文字.

这是实现(comparisons.cpp)

int strcmp_custom(const char* a, const char* b) {
    while (*b == *a) {
        if (*a == '\0') return 0;
        a++;
        b++;
    }
    return *b - *a;
}
Run Code Online (Sandbox Code Playgroud)

这是测试驱动程序(driver.cpp):

#include "comparisons.h"

#include <array>
#include <chrono>
#include <iostream>

void init_string(char* str, int nChars) {
    // 10% of strings will be equal, and 90% of strings will have one char different.
    // This way, many strings will share long prefixes …
Run Code Online (Sandbox Code Playgroud)

c++ string performance

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

如何在java中通过引用传递值

public class JavaApplication6 {

    public static void a(int b)
    {
        b++;
    }
Run Code Online (Sandbox Code Playgroud)

我正在调用函数a并传递变量b,目的是像C++引用(&b)一样递增它.这会有用吗?如果没有,为什么?

    public static void main(String[] args) {

        int b=0;
        a(b);
        System.out.println(b);
    }

}
Run Code Online (Sandbox Code Playgroud)

java function parameter-passing

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

C ++和Python之间的数据传输

我想在C ++和Python之间共享内存。

我的问题:

  1. 我正在使用C ++处理大数据集(最大6 GB的RAM)。所有计算均在c ++中完成。
  2. 然后,我想将所有结果“粘贴”到Python程序中。但是我只能将数据写入磁盘,然后从Python读取该文件,效率不高。

有什么办法可以“映射”与C ++变量相对应的内存,以便我可以从Python访问数据?我不想将6GB的数据复制到硬盘上。

c++ python data-transfer

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

程序选择'\ 0'即使没有提到 - 澄清

所以,我可以预测这个程序会做什么:

int main()
{
   char d[] = {'h','e','l','l','o'};
   const char *c = d;
   std::cout << *c << std::endl;
   while ( *c ) {
      c = c + 1;
      std::cout << *c << std::endl;
      if ( *c == '\0' )
         std::cout << "Yes" << std::endl;
   }
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

从我的理解,代码应该永远不会打印因为\0字符数组中没有d[],所以这个程序正在采摘的垃圾值是什么?我做了这个,同时应该无限次地运行.是对的吗?

c++ arrays

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

这是在C++中启动线程的正确方法吗?

这是我用来启动线程的方法,但是我觉得这种方式有任何缺点.

void myFunc()
{
    //code here

}


unsigned int _stdcall ThreadFunction(void* data)
{
    myFunc();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我使用的主要功能:

HANDLE A = (HANDLE)_beginthredex(0,0,&ThreadFunction,0,0,0);
Run Code Online (Sandbox Code Playgroud)

我结束了这个主题CloseHandle(A);.

c++ multithreading

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