在内存分配限制在Windows +我在这个计算正确? [英] Limit on memory allocation in windows + am I calculating this properly?
问题描述
我在写这需要大量的内存(大图分析)的程序。
I'm writing a program that requires a lot of memory (large graph analysis).
目前有两种主要的数据结构在我的节目(占用大部分内存)。它们是:
Currently there are two main data structures in my program (taking up most of the memory). These are:
- 类型的n * n的矩阵
INT **
- 和长度为n的数组,键入
节点*
- a n*n matrix of type
int **
- and array of length n, type
Node *
节点,在这种情况下,是一个包含两个整数的结构体(的sizeof(节点)
= 8)
Node, in this case, is a struct containing two ints (sizeof(Node)
= 8)
对于n,我可以运行我的code最大的值是22900,做了一些计算,我得到:
The biggest value for n that I can run my code on is 22900, doing a bit of calculation I get:
22900 * 22900 *的sizeof(int)的* 8 + 22900 * sizeof运算(节点)= 16782591360位
这是1.95375077千兆字节。
This is 1.95375077 Gigabytes.
所以,问题1:我在计算这两个数据结构正确的内存使用情况?
2:有没有在Windows上2GB的内存分配限制。如果是这样,我怎么能解决呢?
So question 1: am I calculating the memory usage for these two data structures properly? and 2: Is there a 2GB memory allocation limit on windows. If so, how can I get around it?
有关详细信息,我是在64位的Windows 7机器用gcc编译,4GB内存与可用RAM〜3GB的运行时间。
For further information, I am on a 64bit Windows 7 machine compiling with GCC, 4GB RAM with ~3GB of free RAM at time of running.
感谢。
推荐答案
您不能正确计算它。第一,没有理由被8乘以任何分配在C中的量子是字节,而不是位。其次,你忽略了指针数组它实现了你的矩阵的第一维。所以:
You aren't calculating it correctly. First, there is no reason to multiply anything by 8. The quantum of allocation in C is byte, not bit. Second, you neglect the pointer array which implements the first dimension of your matrix. So:
22900 * sizeof(int*) + 22900*22900*sizeof(int) + 22900*sizeof(Node) = 2097914800 bytes
至于有用的意见,我会留给了(已贴),对方的回答。
As for useful advice, I'll leave that to the (already posted) other answer.
这篇关于在内存分配限制在Windows +我在这个计算正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!