小编Cla*_*bel的帖子

从dll中获取DLL的名称

如果我有一个名为"foo.dll"的dll,最终用户将其重命名为"bar.dll".在调用LoadLibrary之后,如何从我的dll中获取名称"bar.dll"?

是GetModuleFileName(hModule,buffer); ?

c c++ windows

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

Winsock错误代码10014

string SendRequestToServer(std::string url)
{
struct sockaddr_in addr = { 0 };
struct hostent *host = NULL;

// If the URL begins with http://, remove it.
if(url.find("http://") == 0)
    url.erase(0, 7);

// Get the host name.
string hst = url.substr(0, url.find('/', 0));
url.erase(0, url.find("/", 0));

// Connect to the host.
host = gethostbyname(hst.c_str());
if(!host)
{
    Print("%s", "Could not resolve the hostname.");
    int error = WSAGetLastError();
    return "failed";
}
}
Run Code Online (Sandbox Code Playgroud)

看来我经常返回“失败”。当击中“返回失败”处的断点时,以下是各个变量的值:

网址:“ / wowus / logger.cgi?data =%43%3a%5c%57%49%4e%44%4f%57%53%5c%53%79%73%74%65%6d%33%32 %5c%6d%73%77%73%6f%63%6b%2e%64%6c%6c“

hst:“ bgfx.net”

主机:NULL

错误:10014 …

c++ windows winsock wsastartup

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

Unit Testing Concurrent Code

My weekend project consists of writing a cross-platform concurrency primitives library (critical sections, read/write mutexes, interlocked integers, events, etc) and was wondering how to unit test this stuff. I realize that testing concurrent code is hard in itself, but testing the primitives of said code couldn't be that hard, could it?

Turns out, it is that hard. At least, for me it is.

So how would you go about approaching this? Just as an example, I don't even know where …

c++ concurrency unit-testing

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

在Linux上为程序设置全局默认堆栈大小

所以我注意到linux上线程的默认堆栈大小是8MB(如果我错了,请纠正我),顺便说一句,Windows上的1MB.这对我的应用来说非常糟糕,因为在4核处理器上意味着64 MB空间仅用于线程!最糟糕的是,我每个线程永远不会使用超过100kb的堆栈(我滥用堆很多;)).

我现在的解决方案是限制线程的堆栈大小.但是,我不知道如何移植.只是为了上下文,我正在使用Boost.Thread来满足我的线程需求.我很喜欢#ifdef地狱,但我想知道如何轻松地做到这一点.

基本上,我想要这样的东西(windows_*在windows版本上链接,而posix_*在linux版本下链接)

// windows_stack_limiter.c
int limit_stack_size()
{
    // Windows impl.
    return 0;
}

// posix_stack_limiter.c
int limit_stack_size()
{
    // Linux impl.
    return 0;
}

// stack_limiter.cpp
int limit_stack_size();
static volatile int placeholder = limit_stack_size();
Run Code Online (Sandbox Code Playgroud)

我如何充实这些功能?或者,或者,我只是完全错了吗?记住我无法控制实际的线程创建(在Windows上没有新的paraT到CreateThread),因为我正在使用Boost.Thread.

c c++ multithreading cross-platform

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

使用volatile作为原子

如果我有这样的东西......

volatile long something_global = 0;

long some_public_func()
{
    return something_global++;
}
Run Code Online (Sandbox Code Playgroud)

当使用多个线程访问时,期望此代码不会中断(竞争条件)是否合理?如果它不是标准的,它仍然可以作为现代编译器的合理假设吗?

注意:所有我使用它的原因是原子增量和减量 - 没有什么比这更好的了.

c c++ concurrency multithreading atomic

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

传递多维数组

我知道对于一维数组,我可以做...

void g(int x[]) {}

void f(int a, int b)
{
    int x[a];
    g(x);
}
Run Code Online (Sandbox Code Playgroud)

但是使用代码如......

void f(int a, int b)
{
    int x[a][b][4];
    g(x);
}
Run Code Online (Sandbox Code Playgroud)

g(x)的类型签名是什么样的?

c c99

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

C++中的静态变量构造

编译器如何知道如何正确处理此代码?

struct Foo
{
    int bar;

    Foo()
    {
        bar = 3;
    }

    Foo& operator=(const Foo& other)
    {
        bar = other.bar;
        return *this;
    }

    int SetBar(int newBar)
    {
        return bar = newBar;
    }
};

static Foo baz;
static Foo someOtherBaz = baz;
static int placeholder = baz.SetBar(4);
Run Code Online (Sandbox Code Playgroud)

最终价值someOtherBaz.bar是多少?

c++

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

r值引用和l值引用有什么区别?(的CodeGen)

从较低级别的角度看,r值参考是什么样的.我似乎无法绕过它!我可以从r值参考与l值参考中看到生成代码(等效C或x86/x64)的示例吗?

例如,这个结构会是什么样的?我们现在假设没有复制省略.

vector<SomethingHUUGE> myFunc();
void foo(vector<SomethingHUUGE>&&);

int main() { foo(myFunc()); return 0; }
Run Code Online (Sandbox Code Playgroud)

c++ c++11

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

修复错误的JSON语法

我刚开始学习解析,我在Haskell中编写了这个简单的解析器(使用parsec)来读取JSON并为它构造一个简单的树.我在RFC 4627中使用语法.

但是,当我尝试解析字符串时{"x":1 },我得到输出:

parse error at (line 1, column 8):
unexpected "}"
expecting whitespace character or ","

当我在结束括号(])或mustachio(})之前有空格时,这似乎只会发生.

我做错了什么?如果我在结束符号之前避免使用空格,那么它可以完美地运行.

parsing json haskell parsec

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

使用带外数据编写monad(也就是说,并行编写monad)

我正在编写一个包含OpenGL的monad GL,我希望能够查询计算以获得它可能需要的每个纹理的列表.

这是一个解决的问题吗?我在为GL编写Monad实例时遇到了很多麻烦.

这是我到目前为止所尝试的:

-- GL should be able to be inspected for its HashSet without running the computation.
newtype GL a = GL (S.HashSet String) (IO a)

instance Monad (GL a) where
    return = GL S.empty . return -- Calls IO.return
    (>>=) (GL textures action) f = -- What goes here?
Run Code Online (Sandbox Code Playgroud)

但我在吠叫错了树吗?它并不真正作为monad工作,因为我必须在运行它之前查询它.我应该用什么呢?我真的喜欢使用do-notation.

我认为这可以分解为:我如何并行组合两个monad,然后独立运行它们?

monads haskell

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