
Memory-mapped file objects behave like both bytearray and likefile objects. You can use mmap objects in most placeswhere bytearray are expected; for example, you can use the remodule to search through a memory-mapped file. You can also change a singlebyte by doing obj[index]=97, or change a subsequence by assigning to aslice: obj[i1:i2]=b'.'. You can also read and write data starting atthe current file position, and seek() through the file to different positions.
« CleanMem 2.5.0 CleanMem Portable 2.5.0 DiskFresh 1.1 » Comment Rules & Etiquette - We welcome all comments from our readers, but any comment section requires some moderation. Some posts are auto-moderated to reduce spam, including links and swear words. When you make a post, and it does not appear, it went into moderation. We use cookies to improve your browsing experience. By continuing to browse our website you agree to our use of cookies. To learn more about how we use cookies, please review our privacy policy here.
A memory-mapped file is created by the mmap constructor, which isdifferent on Unix and on Windows. In either case you must provide a filedescriptor for a file opened for update. If you wish to map an existing Pythonfile object, use its fileno() method to obtain the correct value for thefileno parameter. Otherwise, you can open the file using theos.open() function, which returns a file descriptor directly (the filestill needs to be closed when done).
Note
If you want to create a memory-mapping for a writable, buffered file, youshould flush() the file first. This is necessary to ensurethat local modifications to the buffers are actually available to themapping.
For both the Unix and Windows versions of the constructor, access may bespecified as an optional keyword parameter. access accepts one of fourvalues: ACCESS_READ, ACCESS_WRITE, or ACCESS_COPY tospecify read-only, write-through or copy-on-write memory respectively, orACCESS_DEFAULT to defer to prot. access can be used on both Unixand Windows. If access is not specified, Windows mmap returns awrite-through mapping. The initial memory values for all three access typesare taken from the specified file. Assignment to an ACCESS_READmemory map raises a TypeError exception. Assignment to anACCESS_WRITE memory map affects both memory and the underlying file.Assignment to an ACCESS_COPY memory map affects memory but does notupdate the underlying file.
Changed in version 3.7: Added ACCESS_DEFAULT constant.
To map anonymous memory, -1 should be passed as the fileno along with the length.
(Windows version) Maps length bytes from the file specified by thefile handle fileno, and creates a mmap object. If length is largerthan the current size of the file, the file is extended to contain lengthbytes. If length is 0, the maximum length of the map is the currentsize of the file, except that if the file is empty Windows raises anexception (you cannot create an empty mapping on Windows).
tagname, if specified and not None, is a string giving a tag name forthe mapping. Windows allows you to have many different mappings againstthe same file. If you specify the name of an existing tag, that tag isopened, otherwise a new tag of this name is created. If this parameter isomitted or None, the mapping is created without a name. Avoiding theuse of the tag parameter will assist in keeping your code portable betweenUnix and Windows.
offset may be specified as a non-negative integer offset. mmap referenceswill be relative to the offset from the beginning of the file. offsetdefaults to 0. offset must be a multiple of the ALLOCATIONGRANULARITY.

Raises an auditing eventmmap.__new__ with arguments fileno, length, access, offset.
(Unix version) Maps length bytes from the file specified by the filedescriptor fileno, and returns a mmap object. If length is 0, themaximum length of the map will be the current size of the file whenmmap is called.
flags specifies the nature of the mapping. MAP_PRIVATE creates aprivate copy-on-write mapping, so changes to the contents of the mmapobject will be private to this process, and MAP_SHARED creates amapping that’s shared with all other processes mapping the same areas ofthe file. The default value is MAP_SHARED.
prot, if specified, gives the desired memory protection; the two mostuseful values are PROT_READ and PROT_WRITE, to specifythat the pages may be read or written. prot defaults toPROT_READ|PROT_WRITE.
access may be specified in lieu of flags and prot as an optionalkeyword parameter. It is an error to specify both flags, prot andaccess. See the description of access above for information on how touse this parameter.
offset may be specified as a non-negative integer offset. mmap referenceswill be relative to the offset from the beginning of the file. offsetdefaults to 0. offset must be a multiple of ALLOCATIONGRANULARITYwhich is equal to PAGESIZE on Unix systems.
To ensure validity of the created memory mapping the file specifiedby the descriptor fileno is internally automatically synchronizedwith physical backing store on Mac OS X and OpenVMS.
This example shows a simple way of using mmap:
mmap can also be used as a context manager in a withstatement:
New in version 3.2: Context manager support.
The next example demonstrates how to create an anonymous map and exchangedata between the parent and child processes: Mitti 1 5 5 ml.
Raises an auditing eventmmap.__new__ with arguments fileno, length, access, offset.
Memory-mapped file objects support the following methods:
Closes the mmap. Subsequent calls to other methods of the object willresult in a ValueError exception being raised. This will not closethe open file.
True if the file is closed.
New in version 3.2.
Returns the lowest index in the object where the subsequence sub isfound, such that sub is contained in the range [start, end].Optional arguments start and end are interpreted as in slice notation.Returns -1 on failure.
Changed in version 3.5: Writable bytes-like object How to play witch doctor. is now accepted.
Flushes changes made to the in-memory copy of a file back to disk. Withoutuse of this call there is no guarantee that changes are written back beforethe object is destroyed. If offset and size are specified, onlychanges to the given range of bytes will be flushed to disk; otherwise, thewhole extent of the mapping is flushed. offset must be a multiple of thePAGESIZE or ALLOCATIONGRANULARITY.
None is returned to indicate success. An exception is raised when thecall failed.
Changed in version 3.8: Previously, a nonzero value was returned on success; zero was returnedon error under Windows. A zero value was returned on success; anexception was raised on error under Unix.
Send advice option to the kernel about the memory region beginning atstart and extending length bytes. option must be one of theMADV_* constants available on the system. Ifstart and length are omitted, the entire mapping is spanned. Onsome systems (including Linux), start must be a multiple of thePAGESIZE.
Availability: Systems with the madvise() system call.
Copy the count bytes starting at offset src to the destination indexdest. If the mmap was created with ACCESS_READ, then calls tomove will raise a TypeError exception.
Return a bytes containing up to n bytes starting from thecurrent file position. If the argument is omitted, None or negative,return all bytes from the current file position to the end of themapping. The file position is updated to point after the bytes that werereturned.
Changed in version 3.3: Argument can be omitted or None.
Returns a byte at the current file position as an integer, and advancesthe file position by 1.
Returns a single line, starting at the current file position and up to thenext newline. The file position is updated to point after the bytes that werereturned.
Resizes the map and the underlying file, if any. If the mmap was createdwith ACCESS_READ or ACCESS_COPY, resizing the map willraise a TypeError exception.
Returns the highest index in the object where the subsequence sub isfound, such that sub is contained in the range [start, end].Optional arguments start and end are interpreted as in slice notation.Returns -1 on failure.
Changed in version 3.5: Writable bytes-like object is now accepted.
Set the file’s current position. whence argument is optional anddefaults to os.SEEK_SET or 0 (absolute file positioning); othervalues are os.SEEK_CUR or 1 (seek relative to the currentposition) and os.SEEK_END or 2 (seek relative to the file’s end).
Free slot machine apps for android. Return the length of the file, which can be larger than the size of thememory-mapped area.
Returns the current position of the file pointer.
Write the bytes in bytes into memory at the current position of thefile pointer and return the number of bytes written (never less thanlen(bytes), since if the write fails, a ValueError will beraised). The file position is updated to point after the bytes thatwere written. If the mmap was created with ACCESS_READ, thenwriting to it will raise a TypeError exception.
Changed in version 3.5: Writable bytes-like object is now accepted.
Changed in version 3.6: The number of bytes written is now returned.
Write the integer byte into memory at the currentposition of the file pointer; the file position is advanced by 1. Ifthe mmap was created with ACCESS_READ, then writing to it willraise a TypeError exception.

These options can be passed to mmap.madvise(). Not every option willbe present on every system.
Availability: Systems with the madvise() system call.
Although named after the emerald, which often receives this rectangular cut with trimmed corners, the popular emerald cut design can be applied to many gemstones. It has a range of standard gem sizes for mass-produced jewelry settings. “Emerald Cut Tourmaline,” 4.52 cts, slight color shift. © All That Glitters. Used with permission.
Mass-produced jewelry settings come in standard gem sizes. If a gem won’t fit in a standard setting, you should have a setting custom made. This involves much more labor and, therefore, expense. When purchasing a gem or selecting a cut design, bear this in mind. Under some circumstances, the stone’s value makes cutting for maximum yield worthwhile. You can then pay for a custom setting later. However, in other circumstances, the gem’s value doesn’t justify the cost of a custom setting.
No, a gem doesn’t need to be the precise size of the jewelry setting. A skilled metalsmith can modify a standard setting to accommodate a variety of gem sizes. For example, any round gem can be put in a standard setting. https://truecup360.weebly.com/spooky-spins-tips.html. For other shapes, metalsmiths must consider a variety of factors. As a general rule, gems under one carat can fall within 0.1 mm of the setting size. Over one carat, a 0.2 mm variance can usually be accommodated, sometimes more.
The carat weights given for standard gem sizes in the following chart apply to diamonds cut to ideal proportions. Typically, gem cutters cut colored gemstones with greater volume than diamonds. Thus, they’ll weigh more than the sizes on the chart.
The density or specific gravity (SG) of the material will also affect the weight. For example, a 6.5 mm round diamond, sapphire, and opal, all cut in the same proportions, will all weigh different. The diamond, with an SG of 3.52, will weigh 1 carat. The sapphire, with an SG of 4, will weigh 1.14 carats. The opal, with an SG of 2.15, will only weigh 0.61 carats. (If you know your gemstone density values well, you can estimate the weight of a standard size gem by sight).
There are subtle variations to these values. For example, some charts list a 0.25-carat round diamond as measuring 4.1 mm. Just keep this in mind: don’t take these figures too literally. Use this information as a starting point for estimating weights.
| Rounds | Squares | Ovals | |||
|---|---|---|---|---|---|
| Size | Weight | Size | Weight | Size | Weight |
| 1.6 mm | .02 carat | 5 mm | .75 carat | 5 x 3 mm | .25 carat |
| 2 mm | .03 carat | 6 mm | 1.3 carat | 6 x 4 mm | .5 carat |
| 2.5 mm | .06 carat | 7 mm | 2.05 carat | 7 x 5 mm | 1.0 carat |
| 3 mm | .10 carat | 8 mm | 2.9 carat | 8 x 6 mm | 1.5 carat |
| 3.5 mm | .16 carat | 9 mm | 4.4 carat | 9 x 7 mm | 2.5 carat |
| 4 mm | .25 carat | 10 mm | 6.0 carat | 10 x 8 mm | 3.0 carat |
| 4.5 mm | .33 carat | 11 mm | 8.0 carat | 11 x 9 mm | 4.0 carat |
| 5 mm | .50 carat | 12 mm | 10.35 carat | 12 x 10 mm | 5.0 carat |
| 5.5 mm | .65 carat | 13 mm | 13.2 carat | 14 x 10 mm | 6.0 carat |
| 6 mm | .75 carat | 14 mm | 16.5 carat | 14 x 12 mm | 8.0 carat |
| 6.5 mm | 1.0 carat | 15 mm | 20.25 carat | 16 x 12 mm | 10.5 carat |
| 7 mm | 1.25 carat | 16 mm | 24.6 carat | 18 x 13 mm | 14.2 carat |
| 8 mm | 2.0 carat | 20 x 15 mm | 20.3 carat | ||
| 9 mm | 2.75 carat | 22 x 15 mm | 23.5 carat | ||
| 10 mm | 3.5 carat | 23 x 17 mm | 32.2 carat | ||
| 11 mm | 4.6 carat | 25 x 18 mm | 43.0 carat | ||
| 12 mm | 6.0 carat | 27 x 20 mm | 58.5 carat | ||
| 13 mm | 7.75 carat | 30 x 22 mm | 79.6 carat | ||
| 14 mm | 9.65 carat | ||||
| 15 mm | 11.85 carat | ||||
| 16 mm | 14.35 carat | ||||
| 17 mm | 17.25 carat | ||||
| 18 mm | 20.5 carat | ||||
| 19 mm | 24.0 carat | ||||
| 20 mm | 28.0 carat | ||||
| 21 mm | 34.8 carat | ||||
| 22 mm | 41.8 carat | ||||
| 23 mm | 49.8 carat | ||||
| 24 mm | 57.9 carat | ||||
| 25 mm | 68.7 carat |
| Emerald | Pear | Marquis | |||
|---|---|---|---|---|---|
| 6 x 4 mm | .5 carat | 6 x 5 mm | .7 carat | 4 x 2 mm | .10 carat |
| 7 x 5 mm | 1.0 carat | 7 x 5 mm | .75 carat | 5 x 2.5 mm | .25 carat |
| 8 x 6 mm | 1.5 carat | 8 x 5 mm | 1.0 carat | 6 x 3 mm | .30 carat |
| 9 x 7 mm | 2.5 carat | 9 x 6 mm | 1.5 carat | 8 x 4 mm | .75 carat |
| 10 x 8 mm | 3.0 carat | 10 x 7 mm | 2.0 carat | 10 x 5 mm | 1.0 carat |
| 11 x 9 mm | 4.0 carat | 11 x 7 mm | 2.25 carat | 12 x 6 mm | 2.0 carat |
| 12 x 10 mm | 5.0 carat | 12 x 8 mm | 3.0 carat | 14 x 7 mm | 3.0 carat |
| 14 x 10 mm | 6.0 carat | 13 x 9 mm | 3.5 carat | 16 x 8 mm | 4.0 carat |
| 14 x 12 mm | 8.0 carat | 15 x 10 mm | 5.5 carat | 18 x 9 mm | 6.0 carat |
| 16 x 12 mm | 10.5 carat | 16 x 12 mm | 8.6 carat | 20 x 10 mm | 8.5 carat |
| 18 x 13 mm | 14.2 carat | 18 x 13 mm | 12 carat | ||
| 20 x 15 mm | 20.3 carat | 20 x 15 mm | 17.3 carat | ||
| 25 x 18 mm | 52.2 carat | 22 x 15 mm | 18.7 carat | ||
| 25 x 18 mm | 30.6 carat | ||||
| 30 x 22 mm | 54.5 carat |
For more information on these gem cuts, consult our Guide to Gem Cutting Terms.
