What does the C++ standard state the size of int, long type to be?

I'm looking for detailed information regarding the size of basic C++ types. I know that it depends on the architecture (16 bits, 32 bits, 64 bits) and the compiler. But are there any standards for C++? I'm using Visual Studio 2008 on a 32-bit architecture. Here is what I get: char : 1 byte short : 2 bytes int : 4 bytes long : 4 bytes float : 4 bytes double: 8 bytes I tried to

C ++标准规定int,long类型的大小是什么?

我正在寻找有关基本C ++类型大小的详细信息。 我知道它取决于架构(16位,32位,64位)和编译器。 但是有没有C ++的标准? 我在32位体系结构上使用Visual Studio 2008。 这是我得到的: char : 1 byte short : 2 bytes int : 4 bytes long : 4 bytes float : 4 bytes double: 8 bytes 我试图找到没有太多成功的可靠信息,说明不同架构和编译器下的char , short , int , long , double , float (以及其他类型,

How can I profile C++ code running in Linux?

I have a C++ application, running on Linux, which I'm in the process of optimizing. How can I pinpoint which areas of my code are running slowly? If your goal is to use a profiler, use one of the suggested ones. However, if you're in a hurry and you can manually interrupt your program under the debugger while it's being subjectively slow, there's a simple way to find performa

我如何分析在Linux中运行的C ++代码?

我有一个C ++应用程序,运行在Linux上,我正在优化。 我怎样才能确定我的代码的哪些区域运行缓慢? 如果您的目标是使用分析器,请使用其中一个建议的分析器。 但是,如果您很匆忙,而且在主调慢的情况下可以在调试器中手动中断程序,则有一种简单的方法可以找到性能问题。 只需暂停几次,每次看看调用堆栈。 如果有一些代码浪费了一定比例的时间,20%或50%,或者其他什么,那就是你在每个样本上的行为中可以捕获它的概

What are the rules about using an underscore in a C++ identifier?

It's common in C++ to name member variables with some kind of prefix to denote the fact that they're member variables, rather than local variables or parameters. If you've come from an MFC background, you'll probably use m_foo . I've also seen myFoo occasionally. C# (or possibly just .NET) seems to recommend using just an underscore, as in _foo . Is this allowed by the C+

有关在C ++标识符中使用下划线的规则是什么?

在C ++中通常使用某种前缀命名成员变量,以表示它们是成员变量,而不是局部变量或参数。 如果你来自MFC背景,你可能会使用m_foo 。 我偶尔也见过myFoo 。 C#(或可能只是.NET)似乎建议只使用下划线,如_foo 。 这是由C ++标准允许的吗? 规则(在C ++ 11中没有改变): 保留在任何范围内,包括用作实现宏: 以下划线开头的标识符紧跟着一个大写字母 包含相邻下划线(或“双下划线”)的标识符 保留在全局名称空间

What are POD types in C++?

I've come across this term POD-type a few times. What does it mean? POD stands for Plain Old Data - that is, a class (whether defined with the keyword struct or the keyword class ) without constructors, destructors and virtual members functions. Wikipedia's article on POD goes into a bit more detail and defines it as: A Plain Old Data Structure in C++ is an aggregate class that cont

C ++中的POD类型是什么?

我遇到过这个POD类型的几次。 这是什么意思? POD代表普通旧数据 - 也就是说,一个类(不管是用关键字struct还是关键字class )没有构造函数,析构函数和虚拟成员函数。 维基百科有关POD的文章更详细一点,并将其定义为: C ++中的普通旧数据结构是一个聚合类,它仅包含PODS作为成员,没有用户定义的析构函数,没有用户定义的复制赋值运算符,也没有指向成员类型的非静态成员。 在C ++ 98/03的这个答案中可以找到更详细

How to set input focus to a shown dialog in Qt?

In a button click slot, I create and exec() a dialog with a NULL parent. Inside the dialog's constructor, I have: this->activateWindow(); this->raise(); this->setFocus(); The dialog is application modal and has strong focus. However, it does NOT respond to keyboard events until I click on it. How do I make the dialog get focus without having to click it? The problem was that I

如何将输入焦点设置为Qt中显示的对话框?

在一个按钮单击插槽中,我创建并exec()了一个带有空父对象的对话框。 在对话框的构造函数中,我有: this->activateWindow(); this->raise(); this->setFocus(); 该对话框是应用程序模式,并具有强烈​​的重点。 但是,它不响应键盘事件,直到我点击它。 如何让对话无需点击即可获得焦点? 问题是我设置了Qt:Tool窗口标志。 使用Qt :: Popup或Qt :: Window代替会导致在显示对话框时自动设置输入焦点。 我自己

Porting a project to OpenGL3

I'm working on a C++ cross-platform OpenGL application (Windows, Linux and MacOS) and I am wondering if some of you could share some advices on porting a large application to OpenGL 3. The reason I am looking into OpenGL 3 is because I think we could benefit a lot from using the new "Sync objects". Nvidia has supported such an extension since the Geforce 256 days (gl_nv_fences) but

将项目移植到OpenGL3

我正在研究一个C ++跨平台的OpenGL应用程序(Windows,Linux和MacOS),我想知道是否有些人可以分享一些关于将大型应用程序移植到OpenGL 3的建议。我研究OpenGL 3的原因是因为我认为我们可以从使用新的“同步对象”中获益很多。 Nvidia从Geforce 256天(gl_nv_fences)开始就支持这种扩展,但在OpenGL 3.0 +之前似乎在ATI硬件上没有相应的功能...... 我们的代码使得glut / freeglut,glu函数,OpenGL 2扩展和CUDA(在支持的硬件

C++ template name pretty print

I have need to print indented template names for debugging purposes. For example, instead of single-line, I would like to indent name like this: boost::phoenix::actor< boost::phoenix::composite< boost::phoenix::less_eval, boost::fusion::vector< boost::phoenix::argument<0>, boost::phoenix::argument<1>, I started writing my own but is getting

C ++模板名称漂亮的打印

为了进行调试,我需要打印缩进的模板名称。 例如,而不是单行,我想缩进这样的名字: boost::phoenix::actor< boost::phoenix::composite< boost::phoenix::less_eval, boost::fusion::vector< boost::phoenix::argument<0>, boost::phoenix::argument<1>, 我开始写我自己的,但变得越来越复杂。 有没有现有的解决方案? 如果没有,你能帮我完成我的实施吗? 如果

compiler nested loop optimization for sequential memory access.

I came across a strange performance issue in a matrix multiply benchmark (matrix_mult in Metis from the MOSBENCH suite). The benchmark was optimized to tile the data such that the active working set was 12kb (3 tiles of 32x32 ints) and would fit into the L1 cache. To make a long story short, swapping the inner two most loops had a performance difference of almost 4x on certain array input sizes

用于顺序存储器访问的编译器嵌套循环优化。

我在矩阵乘法基准测试中遇到了一个奇怪的性能问题(MOSBENCH套件中的Metis中的matrix_mult)。 该基准进行了优化以平铺数据,使得活动工作集为12kb(3个32x32整数的图块)并且适合L1缓存。 长话短说,在某些数组输入大小(4096,8192)中,交换内部最多的两个循环的性能差异几乎为4倍,而其他差异大约为30%。 问题基本上是顺序访问元素,而不是跨步模式。 某些数组大小,我认为创建了一个糟糕的跨步访问,产生了很多缓存线冲

Why should I use a pointer rather than the object itself?

I'm coming from a Java background and have started working with objects in C++. But one thing that occurred to me is that people often use pointers to objects rather than the objects themselves, for example this declaration: Object *myObject = new Object; rather than: Object myObject; Or instead of using a function, let's say testFunc() , like this: myObject.testFunc(); we have to

为什么我应该使用指针而不是对象本身?

我来自Java背景,并开始使用C ++中的对象。 但有一件事发生在我身上的是人们经常使用指向对象的指针而不是对象本身,例如这个声明: Object *myObject = new Object; 而不是: Object myObject; 或者用一个函数,比如说testFunc() ,就像这样: myObject.testFunc(); 我们必须写: myObject->testFunc(); 但我无法弄清楚为什么我们应该这样做。 因为我们可以直接访问内存地址,所以我会假设它与效率和速度有关。

Is < faster than <=?

I'm reading a book where the author says that if( a < 901 ) is faster than if( a <= 900 ) . Not exactly as in this simple example, but there are slight performance changes on loop complex code. I suppose this has to do something with generated machine code in case it's even true. No, it will not be faster on most architectures. You didn't specify, but on x86, all of the in

是<快于<=?

我正在读一本书,作者说if( a < 901 )比if( a <= 900 )快。 与这个简单的例子不完全一样,但是在循环复杂代码上有轻微的性能变化。 我想这必须用生成的机器代码来做,以防万一。 不,在大多数架构上它不会更快。 您没有指定,但在x86上,所有整数比较将通常在两个机器指令中实现: test或cmp指令,设置EFLAGS 和一个Jcc (跳转)指令,取决于比较类型(和代码布局): jne - 如果不相等则跳转 - > ZF = 0