7

Given mmap's constructor declaration:

class mmap.mmap(fileno, length[, flags[, prot[, access[, offset]]]])

How do I specify both access & offset?

The documentation states:

access may be specified in lieu of flags and prot as an optional keyword parameter. It is an error to specify both flags, prot and access. See the description of access above for information on how to use this parameter.

So I've tried to do things like

  • mmap.mmap(file_no, length, offset, access=mmap.ACCESS_COPY)
  • mmap.mmap(file_no, length, access=mmap.ACCESS_COPY, offset=offset)

    m = mmap.mmap(f.fileno(), 4, access=mmap.ACCESS_COPY, offset=2)
    Traceback (most recent call last):
    File "", line 1, in mmap.error: [Errno 22] Invalid argument

  • mmap.mmap(file_no, length, mmap.ACCESS_COPY, offset)

But I can't get it to work. Why is this confusing me so much?

2
  • The following looks correct: mmap.mmap(file_no, length, access=mmap.ACCESS_COPY, offset=offset). What happens when you try it? Commented Jun 7, 2012 at 14:14
  • Updated question to show you. just an invalid argument error (and yes, it works if I take away the offset=2) Commented Jun 7, 2012 at 14:16

2 Answers 2

6

This error is unrelated to access. As documented, the offset just must be a multiple of mmap.PAGESIZE or mmap.ALLOCATIONGRANULARITY.

Sign up to request clarification or add additional context in comments.

1 Comment

Right, that makes sense. I confused myself when m = mmap.mmap(f.fileno(), 4, mmap.MAP_SHARED, mmap.PROT_READ | mmap.PROT_WRITE, 2) seemed to work. Thanks.
1

try with:

m = mmap.mmap(f.fileno(), 4, access=mmap.ACCESS_COPY, offset=2 * mmap.ALLOCATIONGRANULARITY)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.