java.lang.Object | |
↳ | android.os.MemoryFile |
MemoryFile is a wrapper for the Linux ashmem driver. MemoryFiles are backed by shared memory, which can be optionally set to be purgeable. Purgeable files may have their contents reclaimed by the kernel in low memory conditions (only if allowPurging is set to true). After a file is purged, attempts to read or write the file will cause an IOException to be thrown.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
MemoryFile constructor.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Enables or disables purging of the memory file.
| |||||||||||
Closes and releases all resources for the memory file.
| |||||||||||
Creates a new InputStream for reading from the memory file.
| |||||||||||
Creates a new OutputStream for writing to the memory file.
| |||||||||||
Is memory file purging enabled?
| |||||||||||
Returns the length of the memory file.
| |||||||||||
Reads bytes from the memory file.
| |||||||||||
Write bytes to the memory file.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Is called before the object's memory is being reclaimed by the VM.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
|
MemoryFile constructor.
name | optional name for the file (can be null). |
---|---|
length | of the memory file in bytes. |
Enables or disables purging of the memory file.
allowPurging | true if the operating system can purge the contents of the file in low memory situations |
---|
IOException |
---|
Closes and releases all resources for the memory file.
Creates a new InputStream for reading from the memory file.
Creates a new OutputStream for writing to the memory file.
Is memory file purging enabled?
Returns the length of the memory file.
Reads bytes from the memory file. Will throw an IOException if the file has been purged.
buffer | byte array to read bytes into. |
---|---|
srcOffset | offset into the memory file to read from. |
destOffset | offset into the byte array buffer to read into. |
count | number of bytes to read. |
IOException |
---|
Write bytes to the memory file. Will throw an IOException if the file has been purged.
buffer | byte array to write bytes from. |
---|---|
srcOffset | offset into the byte array buffer to write from. |
destOffset | offset into the memory file to write to. |
count | number of bytes to write. |
IOException |
---|
Is called before the object's memory is being reclaimed by the VM. This can only happen once the VM has detected, during a run of the garbage collector, that the object is no longer reachable by any thread of the running application.
The method can be used to free system resources or perform other cleanup
before the object is garbage collected. The default implementation of the
method is empty, which is also expected by the VM, but subclasses can
override finalize()
as required. Uncaught exceptions which are
thrown during the execution of this method cause it to terminate
immediately but are otherwise ignored.
Note that the VM does guarantee that finalize()
is called at most
once for any object, but it doesn't guarantee when (if at all) finalize()
will be called. For example, object B's finalize()
can delay the execution of object A's finalize()
method and
therefore it can delay the reclamation of A's memory. To be safe, use a
ReferenceQueue, because it provides more control
over the way the VM deals with references during garbage collection.