Class FragmentedMemory

    • Constructor Detail

      • FragmentedMemory

        public FragmentedMemory()
        Default constructor, fragmented memory initially empty.
    • 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 region
        pNumberOfFragments - 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
      • writeBytesToFileChannel

        public long writeBytesToFileChannel​(FileChannel pFileChannel,
                                            long pFilePositionInBytes)
                                     throws IOException
        Description copied from interface: ReadWriteBytesFileChannel
        Writes the whole contents of this memory object at a given offset of a file channel.
        Specified by:
        writeBytesToFileChannel in interface ReadWriteBytesFileChannel
        Parameters:
        pFileChannel - file channel
        pFilePositionInBytes - 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 IOException
        Description copied from interface: ReadWriteBytesFileChannel
        Writes data at a given range from this memory object at a given offset of a file channel.
        Specified by:
        writeBytesToFileChannel in interface ReadWriteBytesFileChannel
        Parameters:
        pBufferPositionInBytes - offset in memory object
        pFileChannel - file channel
        pFilePositionInBytes - file channel offset
        pLengthInBytes - 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: ReadWriteBytesFileChannel
        Reads data into this memory object for a certain position of a file channel.
        Specified by:
        readBytesFromFileChannel in interface ReadWriteBytesFileChannel
        Parameters:
        pFileChannel - file channel
        pFilePositionInBytes - offset in file channel
        pLengthInBytes - 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:
        readBytesFromFileChannel in interface ReadWriteBytesFileChannel
        Parameters:
        pBufferPositionInBytes - offset in memory object
        pFileChannel - file channel
        pFilePositionInBytes - offset in file channel
        pLengthInBytes - 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: SizedInBytes
        Return this memory object's size in bytes.
        Specified by:
        getSizeInBytes in interface SizedInBytes
        Returns:
        size in bytes.
      • free

        public void free()
        Description copied from interface: Freeable
        Free this object, which means that the underlying ressources are released.
        Specified by:
        free in interface Freeable
      • isFree

        public boolean isFree()
        Description copied from interface: Freeable
        Returns true if the object has been freed, which usually means that the underlying ressources are not longer available.
        Specified by:
        isFree in interface Freeable
        Returns:
        true if free