c++ uint , unsigned int , 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:
uint和unsigned int有区别吗- 最好使用上述类型之一或仅使用
int因为我读到有人说编译器确实更有效地处理 int 值,但如果我使用int我必须始终检查是否有负 idxs,这很痛苦. - 您认为迭代器更好吗?它比普通索引
vectorx[idx]更有效吗?
- is there a difference between
uintandunsigned int - which is better to use one of the above types or just use
intas I read some people say compiler does handle int values more efficiently, but if I usedintI will have to check always for negative idxs which is pain. - 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
推荐答案
C++ 没有定义像
uint这样的类型.这必须是您的"类型,即在您的代码或某个第三方库中定义的类型.可以猜到它与unsigned int相同.可能是unsigned long int或其他东西.无论如何,你必须自己检查.
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 asunsigned int. Could beunsigned long intthough 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:时间:2019-05-10 标签:c++uint,unsignedint,int
基础教程推荐
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 这个宏可以转换成函数吗? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
