473,387 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to create a process that uses 5Gb of memory?

P
I want to write a platform independent program that would use up at
least 5Gb of memory for testing purposes. How would I do that?

Thanks!

P

Aug 3 '07 #1
13 1474
P wrote, On 03/08/07 21:56:
I want to write a platform independent program that would use up at
least 5Gb of memory for testing purposes. How would I do that?
It won't be very platform independent since most platforms do not have
5GB of memory and many that might will not allow one process to grab
that much. For those platforms that do then try mallocing a 5GB chunk,
if that fails try mallocing 1GB 5 times. Make sure you also write to the
memory otherwise you might not have what has been reported.

Mind you, I find it hard to see why you need to use up that much memory
for testing purposes.
--
Flash Gordon
Aug 3 '07 #2
On 2007-08-06 08:18, Richard <rg****@gmail.comwrote:
Is a char a byte now? I lose track.
A "byte" in C-speak has been defined as the space occupied by a "char"
at least since C89.
In other contexts, a "byte" may be defined differently (e.g., as
"exactly 8 bits").

hp

--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | hj*@hjp.at |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
Aug 6 '07 #3
"Peter J. Holzer" <hj*********@hjp.atwrites:
On 2007-08-06 08:18, Richard <rg****@gmail.comwrote:
>Is a char a byte now? I lose track.

A "byte" in C-speak has been defined as the space occupied by a "char"
at least since C89.
In other contexts, a "byte" may be defined differently (e.g., as
"exactly 8 bits").
So A byte is CHAR_BITS? Which is in 99.999% of the time 8 bits?
Aug 6 '07 #4
Richard wrote:
"Peter J. Holzer" <hj*********@hjp.atwrites:
>On 2007-08-06 08:18, Richard <rg****@gmail.comwrote:
>>Is a char a byte now? I lose track.

A "byte" in C-speak has been defined as the space occupied by a "char"
at least since C89.
In other contexts, a "byte" may be defined differently (e.g., as
"exactly 8 bits").

So A byte is CHAR_BITS?
In C, yes.
Which is in 99.999% of the time 8 bits?
Maybe not quite that much, if you consider the large embedded world, where
the bulk of C programming is currently happenning.

Aug 6 '07 #5
santosh <sa*********@gmail.comwrites:
Richard wrote:
>"Peter J. Holzer" <hj*********@hjp.atwrites:
>>On 2007-08-06 08:18, Richard <rg****@gmail.comwrote:
Is a char a byte now? I lose track.

A "byte" in C-speak has been defined as the space occupied by a "char"
at least since C89.
In other contexts, a "byte" may be defined differently (e.g., as
"exactly 8 bits").

So A byte is CHAR_BITS?

In C, yes.
>Which is in 99.999% of the time 8 bits?

Maybe not quite that much, if you consider the large embedded world, where
the bulk of C programming is currently happenning.
Venturing off topic here, how many of those system is a "byte" not 8
bits?
Aug 6 '07 #6
Richard wrote, On 06/08/07 11:55:
santosh <sa*********@gmail.comwrites:
>Richard wrote:
>>"Peter J. Holzer" <hj*********@hjp.atwrites:

On 2007-08-06 08:18, Richard <rg****@gmail.comwrote:
Is a char a byte now? I lose track.
A "byte" in C-speak has been defined as the space occupied by a "char"
at least since C89.
In other contexts, a "byte" may be defined differently (e.g., as
"exactly 8 bits").
So A byte is CHAR_BITS?
In C, yes.
>>Which is in 99.999% of the time 8 bits?
Maybe not quite that much, if you consider the large embedded world, where
the bulk of C programming is currently happenning.

Venturing off topic here, how many of those system is a "byte" not 8
bits?
I don't know numbers, but certainly the C compiler for the Texas
Instruments TMS320C1x/2x/3x/4x/5x and I believe a lot of the other DSP
chips from other manufacturers as well.
--
Flash Gordon
Aug 6 '07 #7
santosh said:
Richard wrote:
>>
Is a char a byte now? I lose track.

In C a char is always a byte.
Anyone who can go a week (let alone many, many months) in this newsgroup
without learning that a char is defined to be 1 byte wide is either
unable or unwilling to learn.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Aug 6 '07 #8
Richard Heathfield <rj*@see.sig.invalidwrites:
santosh said:
>Richard wrote:
>>>
Is a char a byte now? I lose track.

In C a char is always a byte.

Anyone who can go a week (let alone many, many months) in this newsgroup
without learning that a char is defined to be 1 byte wide is either
unable or unwilling to learn.
Is that you being a snide, self absorbed bighead again, or did you have something to
offer the thread?
Aug 6 '07 #9

"P" <sp************@yahoo.comwrote in message
news:11**********************@l70g2000hse.googlegr oups.com...
>I want to write a platform independent program that would use up at
least 5Gb of memory for testing purposes. How would I do that?

Thanks!
#include <stdio.h>
#include <stdlib.h>

char *encyclopedia;

int main(void)
{
encyclopedia = malloc(5 * 1024 * 1024 * 1024 );
if(!encyclopedia)
{
printf("Out of memory\n");
exit(EXIT_FAILURE);
}
gets(encyclopedia);
printf("Your encylopedia is %s\n", encyclopedia);
return 0;
}

However it is unlikely that you will be lucky enough to run on a platform
with 64 bit ints. So put casts to size_t and l suffixes etc into that
malloc() call until it seems to work.
There are two ways in which this program could fail, unrelated to the main
problem. One is obvious, but the reasoning gets a little hollow at times.
The other is more serious.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Aug 6 '07 #10
Malcolm McLean wrote:
>
"P" <sp************@yahoo.comwrote in message
news:11**********************@l70g2000hse.googlegr oups.com...
>>I want to write a platform independent program that would use up at
least 5Gb of memory for testing purposes. How would I do that?

Thanks!

#include <stdio.h>
#include <stdlib.h>

char *encyclopedia;

int main(void)
{
encyclopedia = malloc(5 * 1024 * 1024 * 1024 );
I suppose you didn't read the previous articles in this thread?
if(!encyclopedia)
{
printf("Out of memory\n");
exit(EXIT_FAILURE);
}
gets(encyclopedia);
No need to recommend dangerous functions to possible newbies.
printf("Your encylopedia is %s\n", encyclopedia);
return 0;
}

However it is unlikely that you will be lucky enough to run on a platform
with 64 bit ints. So put casts to size_t and l suffixes etc into that
malloc() call until it seems to work.
size_t is not guaranteed to be able to hold that value either.

[snip]

Aug 6 '07 #11
"jacob navia" <ja***@jacob.remcomp.frwrote in message
news:46**********************@news.orange.fr...
>
True. I should have added some test along the lines of
if (CHAR_BIT*sizeof(size_t) 33 && s = malloc(...);
That's not guaranteed to work either, even if there's 5GB of memory
available. size_t is only guaranteed to have at least 16 value bits; a
perverse implementation may have a 64-bit address space but a smaller
size_t, meaning you have to malloc() what you need in chunks no larger than
SIZE_MAX. The OP didn't specify he had to have his 5GB in a single
object...

However, I can't see any way a system could have 5GB of memory accessible if
(CHAR_BIT*sizeof(void *)) < 33. Of course, on most systems, sizeof(size_t)
== sizeof(void *), but the interesting cases are where that's not true.

S

--
Stephen Sprunk "Those people who think they know everything
CCIE #3723 are a great annoyance to those of us who do."
K5SSS --Isaac Asimov
--
Posted via a free Usenet account from http://www.teranews.com

Aug 7 '07 #12
Stephen Sprunk wrote:
"jacob navia" <ja***@jacob.remcomp.frwrote in message
news:46**********************@news.orange.fr...
>>
True. I should have added some test along the lines of
if (CHAR_BIT*sizeof(size_t) 33 && s = malloc(...);

That's not guaranteed to work either, even if there's 5GB of memory
available. size_t is only guaranteed to have at least 16 value bits; a
perverse implementation may have a 64-bit address space but a smaller
size_t
How could it? size_t is defined as the result of the sizeof operator,
so the implementation would be limited to 64K objects. Perverse, but
possible I guess.

--
Ian Collins.
Aug 7 '07 #13
On Tue, 07 Aug 2007 08:57:41 +0200, "¬a\\/b" <al@f.gwrote:

this seems compilable in windows

#include <stdlib.h>
#include <stdio.h>
#include <windows.h>

int main(void)
{int i;
char *s[1024];

if(5*1024*1024<=1024 || 1024*1024<=0)
return 0;
for(i=0; i<1024; ++i)
{s[i]=malloc(5*1024*1024);
if(s[i]==0) break;
}
printf("Presa memoria=%gbytes i=%i\n",
i*1024.0*1024.0*5, i);
Sleep(12000);
printf("Esco\n");
if(i>0)
for(--i; i>=0; --i)
free(s[i]);
return 0;
}

Aug 7 '07 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jon Perez | last post by:
Running the following under Linux creates 3 processes instead of 2. Once the started thread exits, 2 processes still remain. Why? import thread from thread import start_new_thread def...
6
by: Ganesh | last post by:
Is there a utility by microsoft (or anyone) to force garbage collection in a process without have access to the process code. regards Ganesh
1
by: Wang E | last post by:
I've been working on an online judge(for ACM/ICPC) using C#.Programmes submitted by users can now be compiled,and it's the problem to judge.I use the Process class in C#,and my thread is as...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
28
by: Jon Davis | last post by:
We're looking at running a memory-intensive process for a web site as a Windows service in isolation of IIS because IIS refuses to consume all of the available physical RAM. Considering remoting to...
7
by: malkarouri | last post by:
Hi everyone, I have written a function that runs functions in separate processes. I hope you can help me improving it, and I would like to submit it to the Python cookbook if its quality is good...
5
by: Brian L. Troutwine | last post by:
Lately I've been tinkering around with Erlang and have begun to sorely want some of its features in Python, mostly the ease at which new processes can be forked off for computation. To that end...
1
by: Kaheru | last post by:
memory utilization increase? This is because when i try to keep track of the CPU utilization and memory utilization of my FTP server process (ftpserver.exe), the CPU utilization increase, but the...
5
by: Max2006 | last post by:
Hi, What is the limit for memory that a .NET process or AppDomain can use? Thank you, Max
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.