C ++ uint,unsigned int,int [英] c++ uint , unsigned int , int

查看:227
本文介绍了C ++ uint,unsigned int,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. 之间有区别吗
  3. 最好使用上述类型之一,或者仅使用int,因为我读到一些人说编译器确实可以更有效地处理int值,但是如果使用int,我将必须始终检查负IDx是痛苦.
  4. 您认为迭代器会更好吗?比普通索引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.

这篇关于C ++ uint,unsigned int,int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆