小编Ray*_*hen的帖子

在各自的线程上运行多个对象似乎多次运行同一个对象

我正在尝试创建一个类的12个新实例并运行它们中的每一个它是一个自己的线程,但它们接缝以共享相同的数据.所有12个实例都位于相同的X和Y位置,但它们每个都应该在随机方向上移动.正如你在代码中看到的,我尝试了各种apraoches,我无法找到原因.

我在这做错了什么?

ps是的...我知道还有一些未使用的变量.在我发布问题之前,我已经看过很多地方了

enemy.cpp

#include "enemy.h"
#include <time.h>
#include <windows.h>



FILE* pEnemyFile = fopen ("enemylog.txt","w");

Enemy::Enemy(const MouseServer& mServer, int& lastMousePosX, int& lastMousePosY, int& winSizeX, int& winSizeY )
    :mouseServer(mServer),
    lastMouseX( ( lastMousePosX ) ? lastMousePosX : 0 ), // evaluate if we get the reference
    lastMouseY( ( lastMousePosY ) ? lastMousePosY : 0 ),
    myPositionX(0),
    myPositionY(0),
    winSizeX(winSizeX),
    winSizeY(winSizeY),
    x(0),
    y(0)
{
    // original source:
    // http://msdn.microsoft.com/en-us/library/windows/desktop/ms682516(v=vs.85).aspx
    // Allocate memory for thread data.
    EDATA threadEnemyData = (EDATA) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,sizeof(enemyData));


    // http://www.codeproject.com/Articles/14746/Multithreading-Tutorial
    // …
Run Code Online (Sandbox Code Playgroud)

c++ oop winapi multithreading object

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

findstr命令用于查找短语而不是单个单词

findstr/S"存储过程"*.*

返回所有带有"stored"字符串的文件,而不是"存储过程".

有谁知道我做错了什么?谢谢

windows search findstr windows-7

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

使用程序集加快一点测试操作

我有一个性能问题 - 我无法击败编译器生成代码的发布版本速度.它慢了25%.我写的函数在我的测试中大约被调用了2000万次,所以让它运行得更快就能获得回报.

C++中的代码非常简单:

static inline char GetBit(char *data, size_t bit)
{ 
    return 0 != (data[bit / 8] & (1 << (bit % 8))); 
}
Run Code Online (Sandbox Code Playgroud)

这是我为64位MASM编写的版本:

mov   rax, rdx  
mov   r10, 8h
xor   rdx, rdx  
div   rax, r10  
mov   al, byte ptr [rax+rcx]  
mov   bl, 1h
mov   cl, dl  
shl   bl, cl  
and   al, bl  
shr   al, cl  
ret 
Run Code Online (Sandbox Code Playgroud)

好吧,我不是一个汇编人员,但我不认为编译器可以使代码更快25%,只是创建更好的汇编.所以诀窍是[可能]在函数调用中.它尊重C++代码的inline关键字并且不生成调用,但我无法使其适用于asm代码:

extern "C" inline char GetBitAsm(char *data, size_t bit);
Run Code Online (Sandbox Code Playgroud)

我使用dumpbin反汇编代码,我可以清楚地看到我的代码+函数调用.虽然没有为编译器的版本生成调用:

mov   rdx, qword ptr [bit]  
mov   rcx, qword ptr …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-construction performance assembly compiler-optimization

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

动态添加视图后如何获取StackLayout的高度?

我有一个 StackLayout(垂直选项是开始)。我需要向它添加一个视图,然后才能获得 StackLayout 的高度。我怎样才能做到这一点?现在,在后面的代码中将视图添加到 StackLayout 后,我​​得到 Height 属性等于 0。

xamarin xamarin.forms

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

Lambda 表达式正确执行,但匿名类定义抛出错误

我想了解Java的Consumer接口。我已经复制了。但是当我用匿名类定义替换 andThen() 方法的返回语句中的 lambda 表达式时,它会抛出 StackOverflowError :

interface Interface<T> {
       
    void accept(T t);

    default Interface<T> andThen(Interface<T> after) {

           //return (T t)->{accept(t); after.accept(t);};//this runs correctly
           
          //below is the anonymous class definition of above lambda expression
          return new Interface<T>(){

            @Override
            public void accept(T t)
            {
                accept(t); //stackoverflow error thrown
                after.accept(t);
            }
          };
     }
}

//Main class:

public class Lambda2 {

    public static void main(String args[]) {
        Interface<String> e1=str -> System.out.println("in e1 - "+str);
    
        Interface<String> e2=str -> System.out.println("in e2 - "+str);
        
        Interface<String> e3 …
Run Code Online (Sandbox Code Playgroud)

java functional-interface

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

Microsoft.Office.Interop.Word命名空间覆盖我的系统命名空间?C#ASP.net

我正在尝试使用Microsoft Office Interops版本11,.NET 2.0修复使用Visual Studio 2003创建的此遗留应用程序.我正在尝试在Visual Studio Express 2010中修复它以引用Interops版本14,.NET 4.0 - 正如我之前关于StackOverflow的问题中所述,遗留应用程序在Windows 7中工作正常,但在我关闭它之后,Microsoft Office产品是当我尝试使用它们时崩溃.

但是,当我修复VS2010中的引用(删除旧的v.11 Interops,添加新的v.14 Interops)然后尝试发布应用程序时,我得到的错误就像

'Microsoft.Office.Interop.Word.System does not contain a definition for IO'
Run Code Online (Sandbox Code Playgroud)

看起来VS2010在引用Word命名空间时没有看到我的System命名空间被使用?当我删除了

using Microsoft.Office.Interop.Word
Run Code Online (Sandbox Code Playgroud)

命名空间然后尝试发布,上面的错误消失了,我只得到与缺少的Word引用相关的预期错误

The type or namespace name '_Document' could not be found (are you missing a using directive or an assembly reference?)
Run Code Online (Sandbox Code Playgroud)

我已经在参考中包含了System.dll,所以我不确定发生了什么?谢谢阅读!

编辑:我使Office Interops的"嵌入式互操作类型"为假.那可能修复了一些错误?但是:Visual Studio仍然将任何系统引用解释为"Microsoft.Office.Interop.Word.System",这不是我想要的.这个错误似乎是现在的主导:

The type name 'Windows' does not exist in the type 'Microsoft.Office.Interop.Word.System'
Run Code Online (Sandbox Code Playgroud)

.net c# primary-interop-assembly ms-office .net-assembly

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

查找总和为指定目标数的所有数字(整数分区)

首先我想说我还在学习,所以我的编程技巧不是很好,我愿意接受你的建议.其次我还在学习英语,所以我想对给您带来的不便表示遗憾.

那么我的问题是这样的,我需要帮助提高我的算法或任何有关它的信息,我不知道该搜索用什么词.

该算法应该找到添加的数字的所有组合等于给定数字.例如:如果我有数字6我的结果应该是:[1,5],[2,4],[2,2,2],[3,3]

我有以下内容:

public List<List<int>> discompose(int number)
    {
        List<List<int>> discomposedPairs = new List<List<int>>();
        if (number <= 3)
            return discomposedPairs;
        int[] numsForCombine = new int[number-1];
        for(int i = 1; i < number;i++){
            numsForCombine[i - 1] = i;
        }
        int ini = 0;
        int end = numsForCombine.Length - 1;
        while (ini <= end)
        {
            List<int> pair = new List<int>();
            pair.Add(numsForCombine[ini++]);
            pair.Add(numsForCombine[end--]);
            discomposedPairs.Add(pair);
        }
        return discomposedPairs;
    }
    public List<List<int>> discomposePair(List<int> pair)
    {
        List<List<int>> parDisc = new List<List<int>>();
        for (int i …
Run Code Online (Sandbox Code Playgroud)

c# algorithm performance combinations

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

我以为static_cast <TYPE>()相当于C++中的TYPE(变量)?

我刚看到一些我不太了解的东西.我认为这static_cast<TYPE>(variable)相当于(或更好/更安全)TYPE(variable).但是,以下代码不起作用

HMENU hMenu = CreateMenu();
HMENU hSubMenu = CreatePopupMenu();

// File
AppendMenu(hSubMenu, MF_STRING, WndClass_main::ID_FILE_EXIT, "&Quit");
AppendMenu(hMenu, MF_STRING | MF_POPUP, static_cast<intptr_t>(hSubMenu), "&File");
Run Code Online (Sandbox Code Playgroud)

我的编译器说它无法转换HMENUintptr_t.我有一个64位系统顺便说一句,这与间铸造interfers void*int?但是,根据我的理解,类型intptr_t(在cstdint中定义)保证足够大void*.

有趣的是,以下(注意不同的演员)有效:

HMENU hMenu = CreateMenu();
HMENU hSubMenu = CreatePopupMenu();

// File
AppendMenu(hSubMenu, MF_STRING, WndClass_main::ID_FILE_EXIT, "&Quit");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (intptr_t)(hSubMenu), "&File");
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

c++ casting

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

'CalucateNumbers'缺少异常规范'noexcept'

我是C++的初学者

我设置头类值时遇到了麻烦.

CalucateNumbers::CalucateNumbers() {
    ResetValues();
}

void CalucateNumbers::ResetValues() {
    firstNumber = 0;
    secondNumber = 8;
}
Run Code Online (Sandbox Code Playgroud)

CalucateNumber 缺少异常规范 noexcept

请帮忙?

这是带有名称的C plus plus Code文件 FBullCowGame.cpp

#include "FBullCowGame.hpp"

FBullCowGame::FBullCowGame() {
    Reset();
}

void FBullCowGame::Reset() {
    CurrentTries = 0;
    MaxTries = 8;
}
Run Code Online (Sandbox Code Playgroud)

这是带有名称的头文件 FBullCowGame.hpp

#ifndef FBullCowGame_hpp
#define FBullCowGame_hpp

#include <stdio.h>
#include <string>

#endif /* FBullCowGame_hpp */


class FBullCowGame {
public:
    void Reset(); // TODO Make a reset void
// Not important.., The important is this ^^
private:
    int CurrentTries;
    int MaxTries; …
Run Code Online (Sandbox Code Playgroud)

c++

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

如何设置替代文字颜色?

我想样式地图区域图像的替代文字颜色 - > alt ="维多利亚的秘密"默认为蓝色,但我想要红色!我尝试了一些没有成功的方法......有什么帮助吗?

这是我的代码:

<map name="Map" id="Map">
        <area shape="rect" coords="22,4,126,50" href="http://www.victoriassecret.com/" target="_blank" alt="Victoria's Secret"/>
Run Code Online (Sandbox Code Playgroud)

html text alt

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