时间:2019-05-10 标签:c++uint,unsignedint,int

c++ uint , unsigned int , int(时间:2019-05-10 标签:c++uint,unsignedint,int)
本文介绍了时间:2019-05-10 标签:c++uint,unsignedint,int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一个程序处理大量向量和这些向量元素的索引,我想知道:

Hi I have a program that deals alot with vectors and indexes of the elements of these vectors, and I was wondering:

  1. uintunsigned int有区别吗
  2. 最好使用上述类型之一或仅使用 int 因为我读到有人说编译器确实更有效地处理 int 值,但如果我使用 int我必须始终检查是否有负 idxs,这很痛苦.
  3. 您认为迭代器更好吗?它比普通索引 vectorx[idx] 更有效吗?
  1. is there a difference between uint and unsigned int
  2. which is better to use one of the above types or just use int as I read some people say compiler does handle int values more efficiently, but if I used int I will have to check always for negative idxs which is pain.
  3. do you think iterators to be better? is it more efficient than normal indexing vectorx[idx]?

p.s 该软件将处理大数据处理,必须具备良好的性能

p.s the software will handle large data processes and good performance is a must have requirement

推荐答案

  1. C++ 没有定义像 uint 这样的类型.这必须是您的"类型,即在您的代码或某个第三方库中定义的类型.可以猜到它与unsigned int 相同.可能是 unsigned long int 或其他东西.无论如何,你必须自己检查.

  1. C++ defines no such type as uint. This must be "your" type, i.e. a type defined in your code or some third party library. One can guess that it is the same as unsigned int. Could be unsigned long int though or something else. Anyway, you have to check it yourself.

这是个人风格的问题.例如,我认为必须使用无符号类型来表示自然的非负值,例如大小或数量.除了一些特定的上下文之外,有符号和无符号类型的性能没有区别.我想说的是,在大多数情况下,处理效率更高的是 unsigned 类型.

It is a matter of personal style. I, for example, believe that one has to use unsigned types to represent naturally non-negative values, like sizes or quantities. There's no difference in performance between signed and unsigned types, aside from some specific contexts. I would say that in most cases it is unsigned types that will be handled more efficiently.

迭代器使实现更加通用,即您可以使用顺序访问迭代器,从而使您的实现适用于任何顺序数据结构.通过使用索引,您对数据结构施加了随机访问要求,这是一个很强的要求.在没有真正需要时强加严格的要求并不是一个好主意.

Iterators make implementations more generic, i.e. you can use sequential-access iterator and thus make your implementation applicable to any sequential data structure. By using index you impose the random-access requirement on the data structure, which is a strong requirement. It is not a good idea to impose strong requirements when there's no real need for them.

这篇关于时间:2019-05-10 标签:c++uint,unsignedint,int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)