开发者

how many integers are in a 16 kb array

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 do开发者_如何转开发uble 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...


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, and long long is 64. What long 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 of T will take by size * 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜