如果我有一个名为"foo.dll"的dll,最终用户将其重命名为"bar.dll".在调用LoadLibrary之后,如何从我的dll中获取名称"bar.dll"?
是GetModuleFileName(hModule,buffer); ?
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 …
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 …
所以我注意到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.
如果我有这样的东西......
volatile long something_global = 0;
long some_public_func()
{
return something_global++;
}
Run Code Online (Sandbox Code Playgroud)
当使用多个线程访问时,期望此代码不会中断(竞争条件)是否合理?如果它不是标准的,它仍然可以作为现代编译器的合理假设吗?
注意:所有我使用它的原因是原子增量和减量 - 没有什么比这更好的了.
我知道对于一维数组,我可以做...
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)的类型签名是什么样的?
编译器如何知道如何正确处理此代码?
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是多少?
从较低级别的角度看,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) 我正在编写一个包含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,然后独立运行它们?
c++ ×7
c ×4
concurrency ×2
haskell ×2
windows ×2
atomic ×1
c++11 ×1
c99 ×1
json ×1
monads ×1
parsec ×1
parsing ×1
unit-testing ×1
winsock ×1
wsastartup ×1