public class

NativeMemoryChunk

extends Object
implements MemoryChunk Closeable
java.lang.Object
   ↳ com.facebook.imagepipeline.memory.NativeMemoryChunk

Class Overview

Wrapper around chunk of native memory.

This class uses JNI to obtain pointer to native memory and read/write data from/to it.

Native code used by this class is shipped as part of libimagepipeline.so @ThreadSafe

Summary

Public Constructors
NativeMemoryChunk(int size)
NativeMemoryChunk()
Public Methods
synchronized void close()
This has to be called before we get rid of this object in order to release underlying memory
void copy(int offset, MemoryChunk other, int otherOffset, int count)
Copy bytes from buffer memory wrapped by this MemoryChunk instance to buffer memory wrapped by another MemoryChunk.
ByteBuffer getByteBuffer()
Gets the ByteBuffer associated with the memory chunk if available, else null.
long getNativePtr()
Gets the pointer the native memory.
int getSize()
Get the size of this memory chunk.
long getUniqueId()
Gets the unique identifier associated with the memory chunk.
synchronized boolean isClosed()
Check if this chunk is already closed
synchronized int read(int memoryOffset, byte[] byteArray, int byteArrayOffset, int count)
Copy bytes from memory to byte array.
synchronized byte read(int offset)
Read byte at given offset.
synchronized int write(int memoryOffset, byte[] byteArray, int byteArrayOffset, int count)
Copy bytes from byte array to buffer.
Protected Methods
void finalize()
A finalizer, just in case.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.facebook.imagepipeline.memory.MemoryChunk
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Public Constructors

public NativeMemoryChunk (int size)

public NativeMemoryChunk ()

Public Methods

public synchronized void close ()

This has to be called before we get rid of this object in order to release underlying memory

public void copy (int offset, MemoryChunk other, int otherOffset, int count)

Copy bytes from buffer memory wrapped by this MemoryChunk instance to buffer memory wrapped by another MemoryChunk. The two MemoryChunks should have the same type.

Parameters
offset number of first byte to copy
other other MemoryChunk to copy to
otherOffset number of first byte to write to
count number of bytes to copy

public ByteBuffer getByteBuffer ()

Gets the ByteBuffer associated with the memory chunk if available, else null.

public long getNativePtr ()

Gets the pointer the native memory.

public int getSize ()

Get the size of this memory chunk. Ignores if this chunk has been closed

public long getUniqueId ()

Gets the unique identifier associated with the memory chunk.

public synchronized boolean isClosed ()

Check if this chunk is already closed

Returns
  • true, if this chunk has already been closed

public synchronized int read (int memoryOffset, byte[] byteArray, int byteArrayOffset, int count)

Copy bytes from memory to byte array.

Parameters
memoryOffset number of first byte to copy
byteArray byte array to copy to
byteArrayOffset number of first byte in byte array to be written
count number of bytes to copy
Returns
  • number of bytes read

public synchronized byte read (int offset)

Read byte at given offset.

Parameters
offset The offset from which the byte will be read
Returns
  • byte at given offset

public synchronized int write (int memoryOffset, byte[] byteArray, int byteArrayOffset, int count)

Copy bytes from byte array to buffer.

Parameters
memoryOffset number of first byte to be written by copy operation
byteArray byte array to copy from
byteArrayOffset number of first byte in byteArray to copy
count number of bytes to copy
Returns
  • number of bytes written

Protected Methods

protected void finalize ()

A finalizer, just in case. Just delegates to close()

Throws
Throwable