我一直在尝试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) 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) 我想在C ++和Python之间共享内存。
我的问题:
有什么办法可以“映射”与C ++变量相对应的内存,以便我可以从Python访问数据?我不想将6GB的数据复制到硬盘上。
所以,我可以预测这个程序会做什么:
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[],所以这个程序正在采摘的垃圾值是什么?我做了这个,同时应该无限次地运行.是对的吗?
这是我用来启动线程的方法,但是我觉得这种方式有任何缺点.
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);.