我是线程的新手,我想知道如何使用它们在非确定性有限自动机中进行评估.
我有调用另一个方法的方法:
public bool Evaluate2(string s)
{
accepted = false;
ThreadEval(s, StartState);
return accepted;
}
Run Code Online (Sandbox Code Playgroud)
变量accepted是一个类成员,我用它来控制其他线程何时应该停止.
void ThreadEval(string s, State q)
{
if (s.Length == 0 && q.IsFinal)
{
accepted = true;
return;
}
bool found = true;
State current = q;
for (int i = 0; found && !accepted && i < s.Length; i++)
{
found = false;
foreach (Transition t in current.transitions)
if (t.symbol == s[i])
{
Thread thread = new Thread(new ThreadStart(delegate { ThreadEval(s.Substring(i+1), t.to); …Run Code Online (Sandbox Code Playgroud) 我有以下代码
#include <string.h>
#include <time.h>
#include <stdio.h>
#define SIZE 100000000
char c[SIZE];
char c2[SIZE];
int main()
{
int i;
clock_t t = clock();
for(i = 0; i < SIZE; i++)
c[i] = 0;
t = clock() - t;
printf("%d\n\n", t);
t = clock();
for(i = SIZE - 1; i >= 0; i--)
c[i] = 0;
t = clock() - t;
printf("%d\n\n", t);
}
Run Code Online (Sandbox Code Playgroud)
我已经运行了一两次,第二次打印总是显示一个较小的值...但是,如果我在其中一个循环中将更改c更改为c2,则两个打印之间的时间差异可以忽略不计......这是什么原因为了这个区别?
编辑:
我已经尝试使用-O3进行编译并查看了程序集:有2次调用memset但第二次仍然打印较小的值.
我正在开发一个使用NI-DAQ的应用程序,以下是提供商提供的一些方法.
void someMethod(Calibration *cal, float myArray[], float result[])
{
newMethod(&cal->rt,myArray,result,cal->cfg.TempCompEnabled);
}
void newMethod(RTCoefs *coefs, double myArray[],float result[],BOOL tempcomp)
{
float newMyArray[6];
unsigned short i;
for (i=0; i < 6; i++)
{
newMyArray[i]=myArray[i];
}
}
Run Code Online (Sandbox Code Playgroud)
我基本上调用someMethod(),为myArray []和result []提供一个包含六个元素([6])的数组.正如你在代码中看到的那样,之后调用newMethod(),并将float myArray [6]传递给double myArray []参数(我真的不明白为什么这段代码的开发人员选择使用双数组,因为在newMethod()中声明的唯一数组是float类型.
现在我的问题出现了:在for循环中,一些值没有任何问题,但是当第四个和第五个值传递给newMyArray []时,它会收到两个值的"-1.#INF0000".乍一看,我认为这将是一些垃圾值,但每次执行时都会出现"-1.#INF0000".
我知道C语言有时会很棘手,但我真的不知道为什么会这样......
char foo[] = "something";
char *p = foo;
Run Code Online (Sandbox Code Playgroud)
有没有办法改变指向的值,只使用一个增加指向下一个元素的指针;?
我的意思是,将这两行的效果放在一个声明中?
*p = 'S';
p++;
Run Code Online (Sandbox Code Playgroud)