分配99%的RAM [英] allocating 99% RAM

查看:96
本文介绍了分配99%的RAM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想要一些我的实验指南。我想在linux中尝试使用swap和ctrl-z来实现
。为了这个我想要
创建一个可以分配几乎所有可用内存资源的ac程序。


到目前为止我已经尝试过使用


#include< stdio.h>


int main(){

int * ip;

while(1){

ip = calloc(sizeof(int));

ip = 312319283;

}

返回0;

}


问题是内存分配不够......(我几乎没有

认为它可以分配任何内存)

我知道我应该免费返回分配的内存,但正如我所说的那样我需要一些帮助。


提前谢谢你,Allan

Hi i would like some guidelines for a experiment of mine. I want to
experiment with the swap and ctrl-z in linux. And for this i want to
create a c program that allocates almost all the free memory resources.

So far i have tried to use

#include <stdio.h>

int main() {
int *ip;
while(1) {
ip = calloc(sizeof(int));
ip = 312319283;
}
return 0;
}

The problem is that the memory allocation is not enough... (i hardly
think it allocates any memory at all)
I know i shoud return the allocated memory with free but as i said i
need some help with this.

Thank you in advance, Allan

推荐答案

你好


查看C手册


calloc需要2个参数


你的程序正在做什么没有定义!


使用


int main(int argc,char * argv [])

{

while (1)

{

int * iP = malloc(sizeof(int));

iP [0] = 12344;

} < br $>
}


你会立刻看到你的记忆已经满了


问候奥拉夫

Hello

Look in the C manual

calloc needs 2 parameters

What your progam is doing is not defined!

use

int main(int argc,char *argv[])
{
while(1)
{
int *iP = malloc(sizeof(int));
iP[0] = 12344;
}
}

you will see your memory is full in no time

Greetings Olaf


al ********** **@spray.se 写道:

您好我想要一些我的实验指南。我想在linux中尝试使用swap和ctrl-z来实现

Hi i would like some guidelines for a experiment of mine. I want to
experiment with the swap and ctrl-z in linux.



你可能需要像glibc等Linux特定的库。

You''d probably need Linux specific libraries like glibc etc.


为此,我想要to $>
创建一个分配几乎所有可用内存资源的ac程序。
And for this i want to
create a c program that allocates almost all the free memory resources.



为什么?一个程序,特别是一个演示,很少需要分配所有可用的内存。


此外,在使用虚拟内存的操作系统下,它没有

gaurunteed 99%的RAM将被提供给你的程序,即使它是b / b
是免费的。操作系统通常会将分配请求远远超过物理RAM,并根据需要将进程的VM页面映射到物理内存。


到目前为止,我试图使用


#include< stdio.h>


int main(){

int * ip;

while(1){

ip = calloc(sizeof(int));
So far i have tried to use

#include <stdio.h>

int main() {
int *ip;
while(1) {
ip = calloc(sizeof(int));



如何确定此代码片段几乎分配所有可用内存!?

它所做的只是覆盖一个分配sizeof的指针(int),

(通常是4个字节)。

How do figure that this code snippet allocates almost all free memory!?
All it does is overwrite a pointer with an allocation of sizeof(int),
(often 4 bytes).


ip = 312319283;

}

返回0;

}


问题是内存分配不够......(我几乎没有

认为它分配任何内存)
ip = 312319283;
}
return 0;
}

The problem is that the memory allocation is not enough... (i hardly
think it allocates any memory at all)



哦是的它分配好了。微不足道地分配和丢失记忆

分期付款。

Oh yes it allocates all right. Allocates and looses memory in miniscule
installments.


我知道我应该免费返回分配的内存,但正如我所说的那样>
需要一些帮助。
I know i shoud return the allocated memory with free but as i said i
need some help with this.



完全不清楚你的计划的总体目标是什么。直到

,你可以更多地了解它,我们做的不仅仅是疯狂的猜测。

It totally unclear what the overall objective of your program is. Until
you can shed more light on that, we can''t do more than make wild
guesses.


感谢您的回复!


我尝试了你的代码,它现在好多了,除了我得到了

Segementation fault ;。有没有办法绕过这个问题在

命令中分配尽可能多的空间而不需要程序chrash?


任何想法都是适当的!
ol ************ @ hotmail.com 写道:
Thank you for your reply!

I tried your code, it works much better now except that i get
"Segementation fault". Is there some way to get around this issue in
order to allocate as much space as i need to without a program chrash?

Any ideas are appriciated!
ol************@hotmail.com wrote:

你好


查看C手册


calloc需要2个参数


你的程序没有定义!


使用


int main(int argc,char * argv [])

{

while(1)

{

int * iP = malloc(sizeof(int));

iP [0] = 12344;

}

}


你会立刻看到你的记忆已经满了


问候Olaf
Hello

Look in the C manual

calloc needs 2 parameters

What your progam is doing is not defined!

use

int main(int argc,char *argv[])
{
while(1)
{
int *iP = malloc(sizeof(int));
iP[0] = 12344;
}
}

you will see your memory is full in no time

Greetings Olaf


这篇关于分配99%的RAM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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