我发现定义WIN32_LEAN_AND_MEAN的解释"通过排除一些不太常用的API来减小Win32头文件的大小".在其他地方,我读到它可以加快构建过程.
那么WIN32_LEAN_AND_MEAN究竟排除了什么?我应该关心这个预处理器指令吗?它是否加快了构建过程?
我还在项目中看到了一个预处理器指令,其名称与额外精益有关.这是我应该知道的另一个深奥的预处理器咒语吗?
我的开发平台是windows 7 x64.我已经安装了VS2012,我想编译一个包含一些Dx11代码的项目.
具体来说,它包括以下文件:
#include <d3dx11.h>
#include <d3dx10.h>
Run Code Online (Sandbox Code Playgroud)
和链接
#pragma comment (lib, "d3dx11.lib")
#pragma comment (lib, "d3dx10.lib")
Run Code Online (Sandbox Code Playgroud)
我已经在我的开发机器上安装了VS2011,但我想在VS2012中尝试使用本机C++的单元测试工具.
由于安装了VS2011并使用DirectShow代码,我安装了Windows 7.1 SDK.
VS2012选择了这个并引用了7.1 SDK,但在VS2012下使用引用的7.1 SDK编译我的项目给出了错误:
"warning C4005: '__useHeader' : macro redefinition"
Run Code Online (Sandbox Code Playgroud)
我用Google搜索了这个,并在social.msdn.microsoft.com上找到了类似我的查询.并且解决方案建议使用Windows 8工具包而不是7.1 SDK进行链接以解决此问题.
Windows 8套件包括d3d11.h之类的标题,但不包括d3dx11.h.
我怎样才能包括与Windows 8的试剂盒,但没有得到多个"宏定义"错误一起d3dx11(从DX SDK)?
我在理解条件变量及其与互斥体的使用方面遇到了一些麻烦,我希望社区可以帮助我.请注意,我来自win32背景,所以我使用CRITICAL_SECTION,HANDLE,SetEvent,WaitForMultipleObject等.
这是我第一次使用c ++ 11标准库进行并发尝试,它是此处的程序示例的修改版本.
#include <condition_variable>
#include <mutex>
#include <algorithm>
#include <thread>
#include <queue>
#include <chrono>
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
std::queue<unsigned int> nNumbers;
std::mutex mtxQueue;
std::condition_variable cvQueue;
bool m_bQueueLocked = false;
std::mutex mtxQuit;
std::condition_variable cvQuit;
bool m_bQuit = false;
std::thread thrQuit(
[&]()
{
using namespace std;
this_thread::sleep_for(chrono::seconds(7));
// set event by setting the bool variable to true
// then notifying via the condition variable
m_bQuit = true;
cvQuit.notify_all();
}
);
std::thread thrProducer( …Run Code Online (Sandbox Code Playgroud) 我正在linux平台上迈出第一步.我安装了Centos x64.我正在尝试构建一个包含几个函数和几个单元测试的小程序.
我使用Netbeans 7.1.2作为开发环境.
以下是构建过程的输出:
CLEAN SUCCESSFUL (total time: 671ms)
"/usr/bin/gmake" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
gmake[1]: Entering directory `/home/john/Dev/GoatsCheese'
"/usr/bin/gmake" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/goatscheese
gmake[2]: Entering directory `/home/john/Dev/GoatsCheese'
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/main.o.d
g++ -m32 -c -g -I/usr/include/cppunit -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++ -m32 -o dist/Debug/GNU-Linux-x86/goatscheese build/Debug/GNU-Linux-x86/main.o
/usr/bin/ld: crt1.o: No such file: No such file or directory
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
编译器设置为创建32位可执行文件,但我不认为这是一个问题(可以在Windows上的x64平台上创建32位可执行文件 - 我熟悉的平台).
Locate在以下位置查找crt1.o文件:
locate crt1.o
/usr/lib64/Mcrt1.o
/usr/lib64/Scrt1.o
/usr/lib64/crt1.o
/usr/lib64/gcrt1.o …Run Code Online (Sandbox Code Playgroud) 我正在为我的游戏物理引擎编写一个vec3类.
我做了一个运算符重载,允许我将一个向量乘以一个标量(以缩放向量):
const vec3 operator*( const real n ) const
{
return vec3(
m_x * n,
m_y * n,
m_z * n
);
}
Run Code Online (Sandbox Code Playgroud)
如果我在计算中使用正确的顺序,这可以正常工作:
float rImpulse;
vec3 vContactNormal;
...
vec3 vImpulse = vContactNormal * rImpulse;
Run Code Online (Sandbox Code Playgroud)
如果我改变乘法的顺序(例如,如果我将标量放在计算中的第一位),那么编译器不喜欢这个并将其突出显示为错误.
我可以更新我的vec3类,因此乘法的顺序无关紧要吗?怎么样?(当我看到答案时,我可能会打我的额头!)
更新
我从vec3类中删除了原来的运算符重载,并在vec3类之外放置了以下两个运算符重载:
const vec3 operator*( const vec3 & v, const real r )
{
return vec3(
v.x() * r,
v.y() * r,
v.z() * r
);
}
const vec3 operator*( const real n, const vec3 & v )
{
return v …Run Code Online (Sandbox Code Playgroud) 假设一台计算机有64k的L1缓存和512k的L2缓存.
程序员已经在主存储器中创建/填充了10mb数据的数组(例如,3d模型的顶点/索引数据).
该数组可能包含一系列结构,如:
struct x
{
vec3 pos;
vec3 normal;
vec2 texcoord;
};
Run Code Online (Sandbox Code Playgroud)
接下来,程序员必须在将数据传递到GPU之前对所有这些数据执行一些操作,例如一次正常计算.
CPU如何决定如何将数据加载到L2缓存中?
程序员如何检查任何给定体系结构的缓存行的大小?
程序员如何确保数据的组织以适应缓存行?
数据对齐字节边界是否可以完成以帮助此过程?
程序员可以做些什么来最小化缓存未命中?
哪些分析工具可以帮助可视化Windows和Linux平台的优化过程?
是否可以访问std :: for_each迭代器,因此我可以使用lambda从std :: list中删除当前元素(如下所示)
typedef std::shared_ptr<IEvent> EventPtr;
std::list<EventPtr> EventQueue;
EventType evt;
...
std::for_each(
EventQueue.begin(), EventQueue.end(),
[&]( EventPtr pEvent )
{
if( pEvent->EventType() == evt.EventType() )
EventQueue.erase( ???Iterator??? );
}
);
Run Code Online (Sandbox Code Playgroud)
我读过关于使用[](typename T :: value_type x){delete x; 这里是SO,但是VS2010似乎不喜欢这个语句(将T作为错误源加下划线).
我想编写一个跨平台(win32和linux)的函数,并返回日期时间的字符串表示[hh:mm:ss dd-mm-yyyy].
知道我只是想以流方式将返回的字符串用作临时字符,如下所示:
std::cout << DateTime() << std::endl;
Run Code Online (Sandbox Code Playgroud)
我考虑使用以下原型编写函数
const char* DateTime();
Run Code Online (Sandbox Code Playgroud)
如果返回字符数组,则必须在完成后将其删除.但我只想暂时,我不想担心取消分配字符串.
所以我编写了一个只返回std :: string的函数:
#include <ctime>
#include <string>
#include <sstream>
std::string DateTime()
{
using namespace std;
stringstream ss;
string sValue;
time_t t = time(0);
struct tm * now = localtime(&t);
ss << now->tm_hour << ":";
ss << now->tm_min << ":";
ss << now->tm_sec << " ";
ss << now->tm_mday + 1 << " ";
ss << now->tm_mon + 1 << " ";
ss << now->tm_year + 1900;
sValue …Run Code Online (Sandbox Code Playgroud) 我正在尝试在RenderMonkey中为Dx9编写一个phong着色器效果.
我在像素着色器中遇到编译错误
*"无效的ps_2_0输入语义'POSITION0'"*
我不知道如何修复它,虽然我知道它必须与VS_OUTPUT中的POSITION0语义有关.
我尝试将VS_OUTPUT的Pos语义更改为TEXCOORD0,但系统会报告
顶点着色器必须最低限度地写入POSITION的所有四个组件
着色器在下面提供.有什么建议?
这是我的顶点着色器:
struct VS_INPUT
{
float4 Pos : POSITION0;
float3 Normal : NORMAL0;
};
struct VS_OUTPUT
{
float4 Pos : POSITION0;
float3 Normal : TEXCOORD0;
};
VS_OUTPUT vs_main( VS_INPUT Input )
{
VS_OUTPUT Output;
Output.Pos = Input.Pos;
Output.Normal = Input.Normal;
return Output;
}
Run Code Online (Sandbox Code Playgroud)
和我的像素着色器:
float4x4 matViewProjection;
// light source
float4 lightPos;
float4 Ambient;
float4 Diffuse;
float4 Specular;
// material reflection properties
float4 Ke;
float4 Ka;
float4 Kd;
float4 Ks;
float nSpecular;
// eye
float4 …Run Code Online (Sandbox Code Playgroud) 我想使用std :: mt19937随机数生成器生成0到255之间的数字列表."一旦选择了数字,它就不应再出现在集合中." - 这就是我不知道该怎么办.这个数学术语逃脱了我(!)
std::mt19937 twister;
std::uniform_int_distribution<int> distribution;
twister.seed(91210);
distribution = std::uniform_int_distribution<int>(0,255);
std::vector vNumbers;
vNumbers.resize(256);
for( int n = 0; n < 256; ++ n )
vNumbers[n] = distribution(twister);
Run Code Online (Sandbox Code Playgroud) c++ ×7
c++11 ×2
directx ×2
caching ×1
concurrency ×1
directx-9 ×1
hlsl ×1
lambda ×1
linker ×1
linux ×1
mutex ×1
optimization ×1
random ×1
rendermonkey ×1
return-value ×1
stl ×1
string ×1
visual-c++ ×1
winapi ×1
windows ×1
windows-8 ×1