467,223 Members | 1,299 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,223 developers. It's quick & easy.

unable to resize mmap object

Hi folks!

I created an mmap object like so:
--- snip ---
from mmap import mmap,MAP_ANONYMOUS,MAP_PRIVATE
fl = file('/dev/zero','rw')
mm = mmap(fl.fileno(), 1, MAP_PRIVATE|MAP_ANONYMOUS)
--- snap ---

Now, when I try to resize mm to 10 byte
--- snip ---
mm.resize(10)
--- snap ---
I get an EnvironmentError:[Errno 22] Invalid argument.

How can I implement a resizeable anonymous memory mapping?
Thanks for your reply!

F. Sidler
Apr 30 '06 #1
  • viewed: 3256
Share:
4 Replies

Fabiano Sidler wrote:
Hi folks!

I created an mmap object like so:
--- snip ---
from mmap import mmap,MAP_ANONYMOUS,MAP_PRIVATE
fl = file('/dev/zero','rw')
mm = mmap(fl.fileno(), 1, MAP_PRIVATE|MAP_ANONYMOUS)
--- snap ---

Now, when I try to resize mm to 10 byte
--- snip ---
mm.resize(10)
--- snap ---
I get an EnvironmentError:[Errno 22] Invalid argument.


Just a guess: try a new size argument that is multiple of page size.

Apr 30 '06 #2
On Sunday 30 April 2006 21:06, Serge Orlov wrote:
Fabiano Sidler wrote:
Now, when I try to resize mm to 10 byte
--- snip ---
mm.resize(10)
--- snap ---
I get an EnvironmentError:[Errno 22] Invalid argument.


Just a guess: try a new size argument that is multiple of page size.


No, doesn't work neitzer. :(

Thank you anyway for the idea!
May 2 '06 #3
Fabiano Sidler wrote:
Hi folks!

I created an mmap object like so:
--- snip ---
from mmap import mmap,MAP_ANONYMOUS,MAP_PRIVATE
fl = file('/dev/zero','rw')
mm = mmap(fl.fileno(), 1, MAP_PRIVATE|MAP_ANONYMOUS)
--- snap ---

Now, when I try to resize mm to 10 byte
--- snip ---
mm.resize(10)
--- snap ---
I get an EnvironmentError:[Errno 22] Invalid argument.

How can I implement a resizeable anonymous memory mapping?
Thanks for your reply!


Bug in Python. Here's the reason (from the changelog):

- Bug #728515: mmap.resize() now resizes the file on Unix as it did
on Windows.

The mmap module resizes the file in question by calling ftruncate.
Only problem is, you can't truncate /dev/zero. I'm going to file this
as a bug; probably on Unix mmap should only resize the file if it's a
regular file (so fstat it first).

Frankly, I'm not so sure matching Windows behavior is a great idea.
mmap module seems to be having an identity crisis. Is it a low-level
system call, or a high-level, OS-independent way to access files as
blocks of memory? The modules is moving towards the latter (what with
Unix mmap accepting ACCESS-style flags, and now this file-resizing
behavior). I actually favor a two-level approach similar to file I/O:
there would low-level system calls in the os module, and high-level
mmap object. (The high-level object would go all the way. It would
accept a filename rather than a file descriptor, anonymous blocks would
be handled OS-independently, rather than mapping /dev/zero, and so on.)

Carl Banks

May 2 '06 #4
Carl Banks wrote:
Frankly, I'm not so sure matching Windows behavior is a great idea.
mmap module seems to be having an identity crisis. Is it a low-level
system call, or a high-level, OS-independent way to access files as
blocks of memory? The modules is moving towards the latter (what with
Unix mmap accepting ACCESS-style flags, and now this file-resizing
behavior). I actually favor a two-level approach similar to file I/O:
there would low-level system calls in the os module, and high-level
mmap object. (The high-level object would go all the way. It would
accept a filename rather than a file descriptor, anonymous blocks would
be handled OS-independently, rather than mapping /dev/zero, and so on.)


I'm sure that we will gladly accept a patch implementing this approach.

Cheers,
Georg
May 4 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Michael | last post: by
26 posts views Thread by myeates@jpl.nasa.gov | last post: by
13 posts views Thread by George Sakkis | last post: by
1 post views Thread by koara | last post: by
5 posts views Thread by Matias Surdi | last post: by
2 posts views Thread by Neal Becker | last post: by
reply views Thread by Kris Kennaway | last post: by
5 posts views Thread by castironpi | last post: by
reply views Thread by Adict | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.