How can you copy (clone) a string?

Aahz Maruch aahz at panix.com
Tue Oct 3 11:12:27 EDT 2000


In article <mailman.970584859.6491.python-list at python.org>,
 <Peter.Rupp at ual.com> wrote:
>
>Earlier I asked a question about cloning python strings, but neglected 
>to say why I needed it.
>What I'm trying to do is determine how large a user process can be 
>before it runs out of memory.   This is useful in debugging kernel 
>parameter issues in our performance lab where our tests are running out 
>of memory and I have to provide empirical proof that the kernel parms 
>are set correctly and that an example program can prove it.   
>
>Originally, I created a one-meg string, then concatenated it to itself 
>until I ran out of memory (on the heap).  The number of iterations 
>would give me a close approximation of the maximum date-segment size 
>for a single process.   The problem is, that once the string approaches 
>half or so of the kernel limit, you get a memory error....Python will 
>have to malloc a string that is 1-meg larger than the original 
>string....you get the idea.

Okay, here's a simple (and very rough!) approach:

OneMBstring = 'a' * ( 1024 * 1024 )
stringList = []
i = 1
while 1:
  print "%sMB consumed" % i
  stringList.append(OneMBstring + str(i))
  i = i + 1
-- 
                      --- Aahz (Copyright 2000 by aahz at pobox.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

There's a difference between a person who gets shit zie doesn't
deserve and a person who gets more shit than zie deserves.  --Aahz



More information about the Python-list mailing list