如何malloc 2G ram?在freebsd中,win2k [英] how to malloc 2G ram? in freebsd, win2k

查看:53
本文介绍了如何malloc 2G ram?在freebsd中,win2k的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我尝试使用malloc 2G大小的mem。所以我喜欢这样的代码。

它在freebsd 5.3和win2k中失败了


我的代码中有什么错误?我怎么能改变它?


谢谢大家:)

benjiam

/////////// ////////////////////////////////////

#include< iostream>

使用命名空间std;


#include< cstdlib>

const int len = 2000;

int main()

{

char * p1 [len];

static int size = int(1<< 20) ;

cout<<尺寸<< endl;

for(int i = 0; i< len; i ++)

{

p1 [i] = new char [size ];

cout<<尺寸<< endl;

char * tp = p1 [i];

for(int x = 0; x<(size-1); x ++)

{

// cout<< x<< endl;

*(tp + x)= char((x%26)+ 48);


}

* (tp + size-1)= 0;

cout<< p [" << i<< "]确定] << endl;

}


for(int i = 0; i< len; i ++)

{

删除[] p1 [i];

}

返回0;

}

/ ///////////////////////////////////////////

解决方案

ch ********** *@hotmail.com 写道:


我尝试malloc 2G大小的mem。所以我喜欢这样的代码。


您无法保证可以这样做。您需要为您的实施检查

新闻组,邮件列表或技术支持。

它在freebsd 5.3和win2k中失败
什么是bug在我的代码?我怎么能改变它?


我们真的无能为力,部分是因为你发布到comp.lang.c,其中

我们使用C,你的代码不是C .comp.lang.c ++是一个不同的新闻组

用于另一种语言。


C ++主义的例子有:#include< iostream>
这不是C头。 using namespace std;
这是编译错误。 #include< cstdlib>
这不是C头。 cout<<尺寸<< ENDL;
''cout''和''endl''是未声明的标识符,''<<''是一个

左移运算符,可能不做什么你要。 p1 [i] = new char [size];



''new''是未声明的标识符,以上是编译错误。


还有更多的例子,但我不在乎无聊。


在文章< d1 ********** @ news.yaako.com>,< ch *********** @ hotmail.com>写道:

:我尝试使用malloc 2G大小的mem。所以我喜欢这样的代码。

:它在freebsd 5.3和win2k中失败了


:我的代码中有什么错误?我怎么能改变它?


你是如何编译的?除非你专门编译使用64位

指针,否则通常会有2 GB

进程大小限制。是的,理论上32位你可以得到4 GB而不是2 GB的
,但是保留一半的内存并不罕见

for系统指针。


即使在2 GB范围内,通常会有地址空间

布局问题:您的代码通常不会在虚拟内存中放置地址0

,并且通常会为堆栈预留一个区域

,并且通常会有一个区域保留给

堆,并且通常会有一个或多个保留区域为
for DLL或者等效。您可能必须提供特殊的链接选项或

在可执行映像上运行特殊的后处理器,以便移动这些保留区域以给自己留出最大的空间。


在Unix系统上,通常会有资源限制

阻止你使用大量的内存,除非你覆盖它们或得到

系统管理员覆盖它们。请参阅''ulimit''手册页

以启动自己,以及getrlimit()函数。系统管理员用来控制限制的机制

非常适用于

unix版本;我不知道freebsd的详细信息。


-

熵是概率的对数 - Boltzmann


对不起!我不是prepense

i在c中写它,并在win2k下使用freebsd5.3


in freebsd

p [294] ] ok

1048576

Killed

////////////////////// /////////////////////

#include< stdio.h>

#include< stdlib .h>

const int len = 2000;

int main()

{

char * p1 [ len];

int i = 0;

int x = 0;

static int size = 1<< 20;

printf("%d \ n",size);

for(i = 0; i< len; i ++)

{

p1 [i] =(char *)malloc(size);

printf("%d \ n",size);

char * tp = p1 [i];

for(x = 0; x<(size-1); x ++)

{

// cout<< x<< endl;

*(tp + x)=(char)((x%26)+ 48);


}

*(tp + size-1)= 0;

printf(" p [%d] ok\\\
,i);

}


for(i = 0; i< len; i ++)

{

free(p1 [i]);

}

返回0;

}


//////////// //////////////////////////////


Martin Ambuhl < ma ***** @ earthlink.net>

??????:u6*************@newsread2.news.atl.earthlin k.net ...

ch ********** *@hotmail.com 写道:


我尝试malloc 2G大小的mem。所以我喜欢这样的代码。
你不能保证你可以这样做。您需要检查
新闻组,邮件列表或技术支持以实现。

它在freebsd 5.3和win2k中失败
什么是bug在我的代码?我怎么能改变呢?



我们真的无能为力,部分是因为你发布到了comp.lang.c,我们使用的是C,你的代码是不是C. comp.lang.c ++是一个不同的新闻组
用于不同的语言。

C ++主题的例子是:

#include< iostream> ;


这不是C头。

using namespace std;


这是一个编译错误。

#include< cstdlib>


这不是C标题。

cout<<尺寸<< endl;


''cout''和''endl''是未声明的标识符,''<<''是一个
左移运算符,可能不会做你想做的事。

p1 [i] = new char [size];


''new''是一个未声明的标识符,上面是一个汇编



错误。
还有更多的实例,但我不在乎无聊。



hi
i try to malloc 2G size mem . so i wirte code like that.
it failt in freebsd 5.3 and win2k

what''s bug in my code ? how can i change it ?

thank all :)
benjiam
///////////////////////////////////////////////
#include <iostream>
using namespace std;

#include <cstdlib>
const int len = 2000;
int main()
{
char* p1[len];
static int size = int (1<<20);
cout << size << endl;
for (int i =0 ; i < len ;i++)
{
p1[i] = new char [size];
cout << size << endl;
char *tp = p1[i];
for ( int x =0 ; x< (size-1); x++)
{
//cout << x << endl;
*(tp+x) = char( (x%26)+ 48);

}
*(tp+size-1) =0;
cout << "p [" << i << "]ok" << endl;
}

for (int i =0 ; i < len ;i++)
{
delete [] p1[i];
}
return 0;
}
////////////////////////////////////////////

解决方案

ch***********@hotmail.com wrote:

hi
i try to malloc 2G size mem . so i wirte code like that.
You have no guarantee that you can do so. You need to check in a
newsgroup, mailing list, or tech support for your implementation.
it failt in freebsd 5.3 and win2k
what''s bug in my code ? how can i change it ?
We really can''t help, partially because you posted to comp.lang.c, where
we use C, and your code is not C. comp.lang.c++ is a different newsgroup
for a different language.

Examples of C++isms are: #include <iostream> This is not a C header. using namespace std; This is a compilation error. #include <cstdlib> This is not a C header. cout << size << endl; ''cout'' and ''endl'' are undeclared identifiers, and ''<<'' is a
left-shift operator that probably don''t do what you want. p1[i] = new char [size];


''new'' is an undeclared identifier, and the above is a compilation error.

There are more instances, but I don''t care to be tiresome.


In article <d1**********@news.yaako.com>, <ch***********@hotmail.com> wrote:
: i try to malloc 2G size mem . so i wirte code like that.
:it failt in freebsd 5.3 and win2k

:what''s bug in my code ? how can i change it ?

And how are you compiling? It is fairly common for there to be a 2 GB
process size limit unless you specifically compile to use 64 bit
pointers. Yes, in theory with 32 bits you -could- get to 4 GB instead
of 2 GB, but it is not uncommon for half of the memory to be reserved
for system pointers.

Even within the 2 GB limit, it is common for there to be address space
layout issues: it is common for your code not to be placed at address 0
in virtual memory, and it is common for there to be an area reserved
for the stack, and it is common for there to be an area reserved for
the heap, and it is common for there to be one or more areas reserved
for DLLs or equivilent. You may have to give special linking options or
run special post-processors on the executable image in order to move
these reserved areas to give yourself the maximum amount of room.

On Unix systems it is also common for there to be resource limits that
prevent you from using gobs of memory unless you override them or get
the systems administrator to override them. See the ''ulimit'' man page
to get yourself started, and the getrlimit() functions. The mechanisms
used by the systems administrator to control the limit would very with
unix version; I do not know the details for freebsd.

--
Entropy is the logarithm of probability -- Boltzmann


sorry! i am not prepense
i write it in c , and comp it under win2k and freebsd5.3

in freebsd
p [ 294 ] ok
1048576
Killed
///////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
const int len = 2000;
int main()
{
char* p1[len];
int i =0;
int x =0;
static int size = 1<<20;
printf( "%d \n", size);
for ( i =0 ; i < len ;i++)
{
p1[i] = (char*) malloc (size);
printf( "%d \n", size );
char *tp = p1[i];
for ( x =0 ; x< (size-1); x++)
{
//cout << x << endl;
*(tp+x) = (char)( (x%26)+ 48);

}
*(tp+size-1) =0;
printf( "p [ %d ] ok\n" , i);
}

for ( i =0 ; i < len ;i++)
{
free(p1[i]);
}
return 0;
}

//////////////////////////////////////////

"Martin Ambuhl" <ma*****@earthlink.net>
??????:u6*************@newsread2.news.atl.earthlin k.net...

ch***********@hotmail.com wrote:

hi
i try to malloc 2G size mem . so i wirte code like that.
You have no guarantee that you can do so. You need to check in a
newsgroup, mailing list, or tech support for your implementation.

it failt in freebsd 5.3 and win2k
what''s bug in my code ? how can i change it ?



We really can''t help, partially because you posted to comp.lang.c, where
we use C, and your code is not C. comp.lang.c++ is a different newsgroup
for a different language.

Examples of C++isms are:

#include <iostream>


This is not a C header.

using namespace std;


This is a compilation error.

#include <cstdlib>


This is not a C header.

cout << size << endl;


''cout'' and ''endl'' are undeclared identifiers, and ''<<'' is a
left-shift operator that probably don''t do what you want.

p1[i] = new char [size];


''new'' is an undeclared identifier, and the above is a compilation


error.
There are more instances, but I don''t care to be tiresome.



这篇关于如何malloc 2G ram?在freebsd中,win2k的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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