public final class MemoryIntArray extends Object implements Parcelable, Closeable
The data structure is designed to have one owner process that can read/write. There may be multiple client processes that can only read or read/write depending how the data structure was configured when instantiated. The owner process is the process that created the array. The shared memory is pinned (not reclaimed by the system) until the owning process dies or the data structure is closed. This class is not thread safe. You should not interact with an instance of this class once it is closed.
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static Parcelable.Creator<MemoryIntArray> |
CREATOR |
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_ELIDE_DUPLICATES, PARCELABLE_WRITE_RETURN_VALUE
Constructor and Description |
---|
MemoryIntArray(int size,
boolean clientWritable)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the array releasing resources.
|
int |
describeContents()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation.
|
boolean |
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
int |
get(int index)
Gets the value at a given index.
|
static int |
getMaxSize() |
int |
hashCode()
Returns a hash code value for the object.
|
boolean |
isClosed() |
boolean |
isWritable() |
void |
set(int index,
int value)
Sets the value at a given index.
|
int |
size()
Gets the array size.
|
void |
writeToParcel(Parcel parcel,
int flags)
Flatten this object in to a Parcel.
|
public static final Parcelable.Creator<MemoryIntArray> CREATOR
public MemoryIntArray(int size, boolean clientWritable) throws IOException
size
- The size of the array in terms of integer slots. Cannot be
more than getMaxSize()
.clientWritable
- Whether other processes can write to the array.IOException
- If an error occurs while accessing the shared memory.public boolean isWritable()
public int get(int index) throws IOException
index
- The index.IOException
- If an error occurs while accessing the shared memory.public void set(int index, int value) throws IOException
isWritable()
returns true which means your process is the
owner.index
- The index.value
- The value to set.IOException
- If an error occurs while accessing the shared memory.public int size() throws IOException
IOException
- If an error occurs while accessing the shared memory.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
- If an error occurs while accessing the shared memory.public boolean isClosed()
protected void finalize() throws Throwable
Object
finalize
method to dispose of
system resources or to perform other cleanup.
The general contract of finalize
is that it is invoked
if and when the JavaTM virtual
machine has determined that there is no longer any
means by which this object can be accessed by any thread that has
not yet died, except as a result of an action taken by the
finalization of some other object or class which is ready to be
finalized. The finalize
method may take any action, including
making this object available again to other threads; the usual purpose
of finalize
, however, is to perform cleanup actions before
the object is irrevocably discarded. For example, the finalize method
for an object that represents an input/output connection might perform
explicit I/O transactions to break the connection before the object is
permanently discarded.
The finalize
method of class Object
performs no
special action; it simply returns normally. Subclasses of
Object
may override this definition.
The Java programming language does not guarantee which thread will
invoke the finalize
method for any given object. It is
guaranteed, however, that the thread that invokes finalize will not
be holding any user-visible synchronization locks when finalize is
invoked. If an uncaught exception is thrown by the finalize method,
the exception is ignored and finalization of that object terminates.
After the finalize
method has been invoked for an object, no
further action is taken until the Java virtual machine has again
determined that there is no longer any means by which this object can
be accessed by any thread that has not yet died, including possible
actions by other objects or classes which are ready to be finalized,
at which point the object may be discarded.
The finalize
method is never invoked more than once by a Java
virtual machine for any given object.
Any exception thrown by the finalize
method causes
the finalization of this object to be halted, but is otherwise
ignored.
public int describeContents()
Parcelable
Parcelable.writeToParcel(Parcel, int)
,
the return value of this method must include the
Parcelable.CONTENTS_FILE_DESCRIPTOR
bit.describeContents
in interface Parcelable
Parcelable.CONTENTS_FILE_DESCRIPTOR
public void writeToParcel(Parcel parcel, int flags)
Parcelable
writeToParcel
in interface Parcelable
parcel
- The Parcel in which the object should be written.flags
- Additional flags about how the object should be written.
May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE
.public boolean equals(Object obj)
Object
The equals
method implements an equivalence relation
on non-null object references:
x
, x.equals(x)
should return
true
.
x
and y
, x.equals(y)
should return true
if and only if
y.equals(x)
returns true
.
x
, y
, and z
, if
x.equals(y)
returns true
and
y.equals(z)
returns true
, then
x.equals(z)
should return true
.
x
and y
, multiple invocations of
x.equals(y)
consistently return true
or consistently return false
, provided no
information used in equals
comparisons on the
objects is modified.
x
,
x.equals(null)
should return false
.
The equals
method for class Object
implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x
and
y
, this method returns true
if and only
if x
and y
refer to the same object
(x == y
has the value true
).
Note that it is generally necessary to override the hashCode
method whenever this method is overridden, so as to maintain the
general contract for the hashCode
method, which states
that equal objects must have equal hash codes.
equals
in class Object
obj
- the reference object with which to compare.true
if this object is the same as the obj
argument; false
otherwise.Object.hashCode()
,
HashMap
public int hashCode()
Object
HashMap
.
The general contract of hashCode
is:
hashCode
method
must consistently return the same integer, provided no information
used in equals
comparisons on the object is modified.
This integer need not remain consistent from one execution of an
application to another execution of the same application.
equals(Object)
method, then calling the hashCode
method on each of
the two objects must produce the same integer result.
Object.equals(java.lang.Object)
method, then calling the hashCode
method on each of the
two objects must produce distinct integer results. However, the
programmer should be aware that producing distinct integer results
for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by
class Object
does return distinct integers for distinct
objects. (This is typically implemented by converting the internal
address of the object into an integer, but this implementation
technique is not required by the
JavaTM programming language.)
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public static int getMaxSize()