16 kb 数组中有多少个整数
我问这个问题是因为我正在使用 cuda 在 GPU 上进行编程。共享内存是 16kb ,因此我需要知道我可以创建的最大整数数组是多少?
如果我有 4GB 内存,是否也可以创建一个大约(3,000,000 个整数)的大数组?计算这个的正确方法是什么?是一个整数,在32位操作系统上是4字节,在64位系统上是8B吗?因此,64 位操作系统上的相同整数数组将具有比 32 位操作系统上双倍的内存空间?当涉及到内存空间计算时,我感到迷茫......有人可以“教程”我吗?
我正在使用 c 作为编程语言...
i am asking this question because i am programming on gpus with cuda. the shared memory is 16kb , therefore i need to know what is the maximum sized integer array i can create?
is it also possible to create a large array about (3,000,000 integers) if i have a 4GB memory? what is the right way to calculate this? is an integer which is 4 bytes on a 32 bit OS, is 8B on a 64 bit system? thefore the same array of integers on a 64 bit OS will have the double memory space than on 32 bit OS? i feel lost when it comes to memory space calculation... can anybody "tutorial" me?
i am using c as a programming language...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
整数是 32 位还是 64 位(或其他位)取决于您的处理器、操作系统和编译器设置,以及您使用的确切数据类型。我相信
int
在常见平台上是 32 位,而long long
是 64 位。long
的含义各不相同:在 x86 Linux 上,它是 32 位32 位机器上是 64 位机器,64 位机器上是 64 位机器。不过,我认为 Windows 做了一些不同的事情。在计算大小方面,可以通过size * sizeof(T)
来确定T
的数组需要多少字节;您可以手动将大小乘以数字中的位数除以 8。因此,16kB 内存可以存储 4k 32 位整数或 2k 64 位整数,而 3M 元素数组将需要 12MB 来存储 32 位整数。位整数,64 位为 24MB。您可以独立于硬件选择数据大小。您可能还想查看 C99 的
以获取具有特定位大小的整数类型。Whether integers are 32 or 64 bits (or something else) depends on your processor, OS, and compiler settings, as well as the exact data type you are using. I believe
int
is 32 bits on common platforms, andlong long
is 64. Whatlong
is varies: on x86 Linux, it's 32 bits on a 32-bit machine and 64 bits on a 64-bit machine. I think Windows does something different, though. In terms of computing sizes, you can determine how many bytes an array ofT
will take bysize * sizeof(T)
; by hand, you can multiply the size by the number of bits in the number divided by 8. So, a 16kB memory can store 4k 32-bit integers or 2k 64-bit ones, and a 3M element array will take 12MB for 32-bit integers and 24MB for 64-bit. You can choose the data size independently of your hardware. You might also want to look at C99's<stdint.h>
to get integer types with particular bit sizes.