最大整数数组大小,512mb ram [英] max integer array size with 512mb ram

查看:284
本文介绍了最大整数数组大小,512mb ram的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我有512 MB的内存。我可以在c中声明的最大整数数组大小。

我最近尝试了不同的值并发现虽然我能够创建当我使用它们时,数组大小的值很大,我得到分段错误。错误。


我所知道的答案是答案与我电脑中的实际堆栈大小有关..



可以有人帮我???

解决方案

对此没有硬性和快速的答案。它会动态变化。


(我正在写这个但对它没有那么自信。从来没有读过它的任何地方)

说你的编译器是x位编译器。

现在尝试


MaxArraySize = pow(2,x-1)-1

(我相信它最适合char类型。)


MaxArraySize =(pow(2,x-1))/(sizeof specific_variable_type)-1

(这将适用于diff变量类型)

如果我错了,请告诉我。


问候,

Johny


< blockquote>除非你的操作系统有一个非常具体和确定的内存模型,否则你可以分配的内存量不会很容易计算。


大多数操作系统使用虚拟机内存,并允许过度提交或内存请求,以使生活变得轻松,让事情运行。例如,如果您有512MB内存,您的操作系统可能会让您通过一系列malloc或新请求请求1GB内存。


如果您想了解更多搜索内存管理或以上提交或其他一些可能会有所帮助。


my question is that i have 512 mb ram .What is the max integer array size that i can declare in c.
I recently experimented with different values and found that while i am able to create large values of array size the moment i use them i get "segmentation fault" error.

All i know is that the answer is related to the actual stack size in my computer..


can someone help me???

解决方案

There is no hard and fast answer for this. It changes dynamically.


(I am writing this but not that confident about it. Never Read it any where just worked out)
say your compiler is x bit compiler.
Now try

MaxArraySize=pow(2,x-1)-1
(I Believe it will work best for char type.)

MaxArraySize=(pow(2,x-1))/(sizeof specific_variable_type)-1
(This will work for diff variable type)
Let me know if I am wrong.

Regards,
Johny


The amount of memory you can allocate isn''t going to be something you can easily compute unless your operating system has a very specific and deterministic memory model.

Most OS use virtual memory and also allow over committing or memory requests in order to make life easy and let things run. For instance if you have 512MB ram your OS may let you ask for 1GB ram with a series of malloc or new requests.

If you want to understand more a search for memory management or over commit or some such may be helpful.


这篇关于最大整数数组大小,512mb ram的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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