Changeset 391 for python/trunk/Doc/library/mmap.rst
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/library/mmap.rst
r2 r391 23 23 :func:`os.open` function, which returns a file descriptor directly (the file 24 24 still needs to be closed when done). 25 26 .. note:: 27 If you want to create a memory-mapping for a writable, buffered file, you 28 should :func:`~io.IOBase.flush` the file first. This is necessary to ensure 29 that local modifications to the buffers are actually available to the 30 mapping. 25 31 26 32 For both the Unix and Windows versions of the constructor, *access* may be … … 95 101 ALLOCATIONGRANULARITY. 96 102 103 To ensure validity of the created memory mapping the file specified 104 by the descriptor *fileno* is internally automatically synchronized 105 with physical backing store on Mac OS X and OpenVMS. 106 97 107 This example shows a simple way of using :class:`mmap`:: 98 108 … … 105 115 with open("hello.txt", "r+b") as f: 106 116 # memory-map the file, size 0 means whole file 107 m ap= mmap.mmap(f.fileno(), 0)117 mm = mmap.mmap(f.fileno(), 0) 108 118 # read content via standard file methods 109 print m ap.readline() # prints "Hello Python!"119 print mm.readline() # prints "Hello Python!" 110 120 # read content via slice notation 111 print m ap[:5] # prints "Hello"121 print mm[:5] # prints "Hello" 112 122 # update content using slice notation; 113 123 # note that new content must have same size 114 m ap[6:] = " world!\n"124 mm[6:] = " world!\n" 115 125 # ... and read again using standard file methods 116 m ap.seek(0)117 print m ap.readline() # prints "Hello world!"126 mm.seek(0) 127 print mm.readline() # prints "Hello world!" 118 128 # close the map 119 m ap.close()129 mm.close() 120 130 121 131 … … 126 136 import os 127 137 128 m ap= mmap.mmap(-1, 13)129 m ap.write("Hello world!")138 mm = mmap.mmap(-1, 13) 139 mm.write("Hello world!") 130 140 131 141 pid = os.fork() 132 142 133 143 if pid == 0: # In a child process 134 m ap.seek(0)135 print m ap.readline()136 137 m ap.close()144 mm.seek(0) 145 print mm.readline() 146 147 mm.close() 138 148 139 149 … … 143 153 .. method:: close() 144 154 145 Close the file. Subsequent calls to other methods of the object will 146 result in an exception being raised. 155 Closes the mmap. Subsequent calls to other methods of the object will 156 result in a ValueError exception being raised. This will not close 157 the open file. 147 158 148 159 … … 174 185 Copy the *count* bytes starting at offset *src* to the destination index 175 186 *dest*. If the mmap was created with :const:`ACCESS_READ`, then calls to 176 move will throwa :exc:`TypeError` exception.187 move will raise a :exc:`TypeError` exception. 177 188 178 189 … … 200 211 Resizes the map and the underlying file, if any. If the mmap was created 201 212 with :const:`ACCESS_READ` or :const:`ACCESS_COPY`, resizing the map will 202 throwa :exc:`TypeError` exception.213 raise a :exc:`TypeError` exception. 203 214 204 215 … … 235 246 file pointer; the file position is updated to point after the bytes that 236 247 were written. If the mmap was created with :const:`ACCESS_READ`, then 237 writing to it will throwa :exc:`TypeError` exception.248 writing to it will raise a :exc:`TypeError` exception. 238 249 239 250 … … 243 254 position of the file pointer; the file position is advanced by ``1``. If 244 255 the mmap was created with :const:`ACCESS_READ`, then writing to it will 245 throw a :exc:`TypeError` exception. 246 247 256 raise a :exc:`TypeError` exception.
Note:
See TracChangeset
for help on using the changeset viewer.