Is there a way to get a view into a python array.array()?
<p>I'm generating many largish 'random' files (~500MB) in which the contents are the output of repeated calls to <code>random.randint(...)</code>. I'd like to preallocate a large buffer, write longs to that buffer, and periodically flush that buffer to disk. I am currently using <code>array.array()</code> but I can't see a way to create a view into this buffer. I need to do this so that I can feed the part of the buffer with valid data into <code>hashlib.update(...)</code> and to write the valid part of the buffer to the file. I could use the slice operator but AFAICT that creates a copy of the buffer, which isn't what I want.</p>

<p>Is there a way to do this that I'm not seeing?</p>

<p><strong>Update:</strong></p>

<p>I went with numpy as user42005 and hgomersall suggested. Unfortunately this didn't give me the speedups I was looking for. My dirt-simple C program generates ~700MB of data in 11s, while my python equivalent using numpy takes around 700s! It's hard to believe that that's the difference in performance between the two (I'm more likely to believe that I made a naive mistake somewhere...)</p>
