Class FragmentedMemory
- java.lang.Object
-
- net.haesleinhuepf.clij.coremem.rgc.FreeableBase
-
- net.haesleinhuepf.clij.coremem.fragmented.FragmentedMemory
-
- All Implemented Interfaces:
Iterable<ContiguousMemoryInterface>,FragmentedMemoryInterface,ReadWriteBytesFileChannel,SizedInBytes,Freeable
public class FragmentedMemory extends FreeableBase implements FragmentedMemoryInterface
Fragmented memory objects are lists of contiguous memory regions. Overall, the referenced memory is not necessarily (but can be) contiguous.- Author:
- royer
-
-
Constructor Summary
Constructors Constructor Description FragmentedMemory()Default constructor, fragmented memory initially empty.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description OffHeapMemoryadd(Buffer pBuffer)Adds a NIO buffer to this fragmented memory.voidadd(ContiguousMemoryInterface pContiguousMemoryInterface)Adds a contiguous memory fragment to this fragmented memoryvoidfree()Free this object, which means that the underlying ressources are released.ContiguousMemoryInterfaceget(int pIndex)Returns the contiguous memory at a given index.intgetNumberOfFragments()Returns the number of fragments.longgetSizeInBytes()Return this memory object's size in bytes.booleanisFree()Returns true if the object has been freed, which usually means that the underlying ressources are not longer available.Iterator<ContiguousMemoryInterface>iterator()OffHeapMemorymakeConsolidatedCopy()Returns a consolidated contiguous copy of this fragmented memory - this is done by simply concatenating the contiguous memory regions together in the list order.voidmakeConsolidatedCopy(ContiguousMemoryInterface pDestinationMemory)Consolidates (copies) the contents of this fragmented memory into a given contiguous buffer.longreadBytesFromFileChannel(long pBufferPositionInBytes, FileChannel pFileChannel, long pFilePositionInBytes, long pLengthInBytes)longreadBytesFromFileChannel(FileChannel pFileChannel, long pFilePositionInBytes, long pLengthInBytes)Reads data into this memory object for a certain position of a file channel.voidremove(ContiguousMemoryInterface pContiguousMemoryInterface)Removes a counties fragment from this fragmented memory.static FragmentedMemorysplit(ContiguousMemoryInterface pContiguousMemoryInterface, long pNumberOfFragments)Splits a contiguous memory regions into n pieces of same size (if possible, otherwise the last one is smaller)static FragmentedMemoryInterfacewrap(ContiguousMemoryInterface... pContiguousMemoryInterfaces)Wrap a list of contiguous memory regions into a single fragmented memory.longwriteBytesToFileChannel(long pBufferPositionInBytes, FileChannel pFileChannel, long pFilePositionInBytes, long pLengthInBytes)Writes data at a given range from this memory object at a given offset of a file channel.longwriteBytesToFileChannel(FileChannel pFileChannel, long pFilePositionInBytes)Writes the whole contents of this memory object at a given offset of a file channel.-
Methods inherited from class net.haesleinhuepf.clij.coremem.rgc.FreeableBase
complainIfFreed
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.haesleinhuepf.clij.coremem.rgc.Freeable
complainIfFreed
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
split
public static FragmentedMemory split(ContiguousMemoryInterface pContiguousMemoryInterface, long pNumberOfFragments)
Splits a contiguous memory regions into n pieces of same size (if possible, otherwise the last one is smaller)- Parameters:
pContiguousMemoryInterface- contiguous memory regionpNumberOfFragments- number of fragments- Returns:
- fragmented memory
-
wrap
public static FragmentedMemoryInterface wrap(ContiguousMemoryInterface... pContiguousMemoryInterfaces)
Wrap a list of contiguous memory regions into a single fragmented memory.- Parameters:
pContiguousMemoryInterfaces- array of contiguous memory regions.- Returns:
- fragmented memory
-
get
public ContiguousMemoryInterface get(int pIndex)
Description copied from interface:FragmentedMemoryInterfaceReturns the contiguous memory at a given index.- Specified by:
getin interfaceFragmentedMemoryInterface- Parameters:
pIndex- index- Returns:
- contiguous memory
-
getNumberOfFragments
public int getNumberOfFragments()
Description copied from interface:FragmentedMemoryInterfaceReturns the number of fragments.- Specified by:
getNumberOfFragmentsin interfaceFragmentedMemoryInterface- Returns:
- number of fragments
-
add
public void add(ContiguousMemoryInterface pContiguousMemoryInterface)
Description copied from interface:FragmentedMemoryInterfaceAdds a contiguous memory fragment to this fragmented memory- Specified by:
addin interfaceFragmentedMemoryInterface- Parameters:
pContiguousMemoryInterface- contiguous fragment
-
remove
public void remove(ContiguousMemoryInterface pContiguousMemoryInterface)
Description copied from interface:FragmentedMemoryInterfaceRemoves a counties fragment from this fragmented memory.- Specified by:
removein interfaceFragmentedMemoryInterface- Parameters:
pContiguousMemoryInterface- ?
-
add
public OffHeapMemory add(Buffer pBuffer)
Description copied from interface:FragmentedMemoryInterfaceAdds a NIO buffer to this fragmented memory.- Specified by:
addin interfaceFragmentedMemoryInterface- Parameters:
pBuffer- NIO buffer- Returns:
- the actual contiguous memory used internally.
-
makeConsolidatedCopy
public OffHeapMemory makeConsolidatedCopy()
Description copied from interface:FragmentedMemoryInterfaceReturns a consolidated contiguous copy of this fragmented memory - this is done by simply concatenating the contiguous memory regions together in the list order.- Specified by:
makeConsolidatedCopyin interfaceFragmentedMemoryInterface- Returns:
- consolidated memory
-
makeConsolidatedCopy
public void makeConsolidatedCopy(ContiguousMemoryInterface pDestinationMemory)
Description copied from interface:FragmentedMemoryInterfaceConsolidates (copies) the contents of this fragmented memory into a given contiguous buffer.- Specified by:
makeConsolidatedCopyin interfaceFragmentedMemoryInterface- Parameters:
pDestinationMemory- destination memory
-
writeBytesToFileChannel
public long writeBytesToFileChannel(FileChannel pFileChannel, long pFilePositionInBytes) throws IOException
Description copied from interface:ReadWriteBytesFileChannelWrites the whole contents of this memory object at a given offset of a file channel.- Specified by:
writeBytesToFileChannelin interfaceReadWriteBytesFileChannel- Parameters:
pFileChannel- file channelpFilePositionInBytes- file position- Returns:
- file position past the last written byte.
- Throws:
IOException- Thrown in case of IO problem.
-
writeBytesToFileChannel
public long writeBytesToFileChannel(long pBufferPositionInBytes, FileChannel pFileChannel, long pFilePositionInBytes, long pLengthInBytes) throws IOExceptionDescription copied from interface:ReadWriteBytesFileChannelWrites data at a given range from this memory object at a given offset of a file channel.- Specified by:
writeBytesToFileChannelin interfaceReadWriteBytesFileChannel- Parameters:
pBufferPositionInBytes- offset in memory objectpFileChannel- file channelpFilePositionInBytes- file channel offsetpLengthInBytes- length in bytes- Returns:
- file position past the last written byte.
- Throws:
IOException- Thrown in case of IO problem.
-
readBytesFromFileChannel
public long readBytesFromFileChannel(FileChannel pFileChannel, long pFilePositionInBytes, long pLengthInBytes) throws IOException
Description copied from interface:ReadWriteBytesFileChannelReads data into this memory object for a certain position of a file channel.- Specified by:
readBytesFromFileChannelin interfaceReadWriteBytesFileChannel- Parameters:
pFileChannel- file channelpFilePositionInBytes- offset in file channelpLengthInBytes- length in bytes- Returns:
- File position past the last byte read.
- Throws:
IOException- Thrown in case of IO problem.
-
readBytesFromFileChannel
public long readBytesFromFileChannel(long pBufferPositionInBytes, FileChannel pFileChannel, long pFilePositionInBytes, long pLengthInBytes) throws IOException- Specified by:
readBytesFromFileChannelin interfaceReadWriteBytesFileChannel- Parameters:
pBufferPositionInBytes- offset in memory objectpFileChannel- file channelpFilePositionInBytes- offset in file channelpLengthInBytes- length in bytes- Returns:
- File position past the last byte read.
- Throws:
IOException- Thrown in case of IO problem.
-
getSizeInBytes
public long getSizeInBytes()
Description copied from interface:SizedInBytesReturn this memory object's size in bytes.- Specified by:
getSizeInBytesin interfaceSizedInBytes- Returns:
- size in bytes.
-
free
public void free()
Description copied from interface:FreeableFree this object, which means that the underlying ressources are released.
-
isFree
public boolean isFree()
Description copied from interface:FreeableReturns true if the object has been freed, which usually means that the underlying ressources are not longer available.
-
iterator
public Iterator<ContiguousMemoryInterface> iterator()
- Specified by:
iteratorin interfaceIterable<ContiguousMemoryInterface>
-
-