public class

NativeMemoryChunk

extends Object
implements 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

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, NativeMemoryChunk other, int otherOffset, int count)
Copy bytes from native memory wrapped by this NativeMemoryChunk instance to native memory wrapped by other NativeMemoryChunk
long getNativePtr()
int getSize()
Get the size of this memory chunk.
synchronized boolean isClosed()
Is this chunk already closed (aka freed) ?
synchronized int read(int nativeMemoryOffset, byte[] byteArray, int byteArrayOffset, int count)
Copy bytes from native memory to byte array.
synchronized byte read(int offset)
Read byte at given offset.
synchronized int write(int nativeMemoryOffset, byte[] byteArray, int byteArrayOffset, int count)
Copy bytes from byte array to native memory.
Protected Methods
void finalize()
A finalizer, just in case.
[Expand]
Inherited Methods
From class java.lang.Object
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, NativeMemoryChunk other, int otherOffset, int count)

Copy bytes from native memory wrapped by this NativeMemoryChunk instance to native memory wrapped by other NativeMemoryChunk

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

public long getNativePtr ()

public int getSize ()

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

public synchronized boolean isClosed ()

Is this chunk already closed (aka freed) ?

Returns
  • true, if this chunk has already been closed

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

Copy bytes from native memory to byte array.

Parameters
nativeMemoryOffset 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.

Returns
  • byte at given offset

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

Copy bytes from byte array to native memory.

Parameters
nativeMemoryOffset 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