Fast way to fill memory

  • Thread starter Oliver 'ojo' Bedford
  • Start date
O

Oliver 'ojo' Bedford

Hi!

For testing purposes I would like to fill chunks of memory (say 20M) with
arbitrary data (say bytes with values 1,2,...255,1,...).

What would be the fastest method?

Oliver
 
J

Jürgen Exner

Oliver 'ojo' Bedford said:
For testing purposes I would like to fill chunks of memory (say 20M) with
arbitrary data (say bytes with values 1,2,...255,1,...).

What would be the fastest method?

The easiest method would probably be to define a string with say 256
bytes and then use the x operator to repeat it.
I would guess it would also be quite fast because it uses perl interna
only and doesn't involve a user-level loop.

jue
 
X

Xho Jingleheimerschmidt

Oliver said:
Hi!

For testing purposes I would like to fill chunks of memory (say 20M) with
arbitrary data (say bytes with values 1,2,...255,1,...).

What would be the fastest method?

Oliver

Why do you need the fastest way to do it? What would happen if you used
a method that was merely fast enough?

You should probably fill the memory in a way that is similar to the way
it would be filled in the situation you are constructing the test to
test. For example, by repeated linear .=, or by repeated exponential
..=, or by x operator.


Xho
 
O

Oliver 'ojo' Bedford

Am Mon, 15 Mar 2010 16:00:42 +0000 schrieb bugbear:
If speed is really important (it often isn't) you may be able to
repeatedly "double up" by copying the head of the 20Meg space to itself.

Thanks for the help. I'll try both methods.

Speed is not important in my case - it's just a matter of convenience
(and impatience on my side).

Oliver
 
C

C.DeRykus

Am Mon, 15 Mar 2010 16:00:42 +0000 schrieb bugbear:



  Thanks for the help. I'll try both methods.

  Speed is not important in my case - it's just a matter of convenience
(and impatience on my side).

You may want to reconsider speed on Win32
though if you've seen the recent thread
"Help on string to array":

http://groups.google.com/group/comp...c713aab4e254fdf?hl=en&lnk=gst&q=malloc+Win32#

One speed-up possibility is to grow the string
by doubling:

$max = 20_000_000;
$str = pack "C*",0..255;
do {$str .= $str;} until length $str >= $max;
substr($str, $max-length($str)) = '');
 
C

ccc31807

Hi!

For testing purposes I would like to fill chunks of memory (say 20M) with
arbitrary data (say bytes with values 1,2,...255,1,...).

What would be the fastest method?

Oliver

Use the recursive Fibonacci function, not tail recursive. It calls
itself twice on each iteration, so clogs up memory even for small
values.

use strict;
use warnings;

sub fib
{
my $n = shift;
if ($n <= 1) { return 1; }
else { return (fib($n - 1) + fib($n - 2)); }
}

my $N = $ARGV[0];
my $f = fib($N);
print "$f\n";
exit(0);
 
T

Ted Zlatanov

c> Use the recursive Fibonacci function, not tail recursive. It calls
c> itself twice on each iteration, so clogs up memory even for small
c> values.

Out of curiousity, did you come up with this method for filling memory
on your own? I haven't seen it in the literature. It could be
patentable.

Ted
 
C

ccc31807

Out of curiousity, did you come up with this method for filling memory
on your own?  I haven't seen it in the literature.  It could be
patentable.

Ted

This is the standard recursive definition of Fibonacci, and I can't
take the credit for it.

In Joe Armstrong's book on Erlang, he gives a multi threaded way of
filling memory using threads, which is very easy and interesting.

CC.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top