小编Adr*_*son的帖子

互斥体真的慢了吗?

我已经阅读了很多次,无论是在网络上还是网络上,互斥体都比关键部分/信号量/插入你的首选同步方法慢.但我从未见过任何论文或研究或其他什么来支持这一主张.

那么,这个想法来自哪里?这是神话还是现实?互斥体真的慢吗?

windows multithreading mutex

19
推荐指数
3
解决办法
6724
查看次数

在C++,platform:windows中进行睡眠操作

我想以毫秒为单位执行上述操作.我更喜欢哪个库和函数调用?

TY.

c++ windows sleep

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

如何使用PCRE获取所有匹配组?

我没有使用C的经验,我需要使用PCRE来获得匹配.
这是我的源代码示例:

int test2()
{
    const char *error;
    int   erroffset;
    pcre *re;
    int   rc;
    int   i;
    int   ovector[OVECCOUNT];

    char *regex = "From:([^@]+)@([^\r]+)";
    char str[]  = "From:regular.expressions@example.com\r\n"\
                  "From:exddd@43434.com\r\n"\
                  "From:7853456@exgem.com\r\n";

    re = pcre_compile (
             regex,       /* the pattern */
             0,                    /* default options */
             &error,               /* for error message */
             &erroffset,           /* for error offset */
             0);                   /* use default character tables */

    if (!re) {
        printf("pcre_compile failed (offset: %d), %s\n", erroffset, error);
        return -1;
    }

    rc = pcre_exec (
        re,                   /* …
Run Code Online (Sandbox Code Playgroud)

c regex pcre pattern-matching

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

多态对象列表

我在下面有一个特定的场景。下面的代码应该打印 B 和 C 类的 'say()' 函数并打印 'B say..' 和 'C say...' 但它没有。任何想法.. 我正在学习多态,所以也有评论在下面的代码行中与它相关的几个问题。

class A
{
public:
// A() {}
    virtual void say() { std::cout << "Said IT ! " << std::endl; }
    virtual ~A(); //why virtual destructor ?
};

void methodCall() // does it matters if the inherited class from A is in this method
{
    class B : public A{
    public:
        // virtual ~B(); //significance of virtual destructor in 'child' class
        virtual void say () { // …
Run Code Online (Sandbox Code Playgroud)

c++ polymorphism stl virtual-functions list

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

如果回来的话

我尝试使用short-hand重写此方法,如果:

 public string checkInputParamters(string baseUrl, string owner, string documentId, string user, string secret, string type)
    {
      if (String.IsNullOrEmpty(baseUrl)) 
          return ExceptionsCodes.BASE_URL_CANNOT_BE_NULL_OR_EMPTY.ToString("g");

      if (String.IsNullOrEmpty(owner))
          return ExceptionsCodes.OWNER_CANNOT_BE_NULL_OR_EMPTY.ToString("g");

      return "";
    }
Run Code Online (Sandbox Code Playgroud)

我不能这样做因为返回强迫我在":"iso";"之后加上一个值.

 public string checkInputParamters(string baseUrl, string owner, string documentId, string user, string secret, string type)
    {
       return ((null == baseUrl) || (string.Empty == baseUrl)) ? ExceptionsCodes.BASE_URL_CANNOT_BE_NULL_OR_EMPTY.ToString("g");
       return ((null == owner) || (string.Empty == owner)) ? ExceptionsCodes.OWNER_CANNOT_BE_NULL_OR_EMPTY.ToString("g");
    }
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

c#

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

C数组和指针

刚开始学习C语言.我有一个指针数组int*parr,我需要用随机数填充它,然后用它做一些其他的事情.但我甚至不明白如何用随机数填充它.我试过这样的东西,但它挂起了程序:

for(i=0 ; i<R ; i++)
{
  for(j=0 ; j<C; j++)
    {
    *(parr+i*C+j)=rand() % 10;
    printf("%d",*(parr+i*C+j));
    }
  printf("\n");
}
Run Code Online (Sandbox Code Playgroud)

c arrays pointers

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