MemoryBuffer
public class MemoryBuffer : Sequence
MemoryBuffer provides simple read-only access to a block of memory, and
provides simple methods for reading files and standard input into a memory
buffer. In addition to basic access to the characters in the file, this
interface guarantees you can read one character past the end of the file,
and that this character will read as ‘\0’.
The ‘\0’ guarantee is needed to support an optimization – it’s intended to be more efficient for clients which are reading all the data to stop reading when they encounter a ‘\0’ than to continually check the file position to see if it has reached the end of the file.
-
Creates a
MemoryBufferwith the contents ofstdin, stopping onceEOFis read.Throws
MemoryBufferErrorif there was an error on creation.Declaration
Swift
public static func fromStdin() throws -> MemoryBuffer -
Creates a
MemoryBufferthat points to a specifiedUnsafeBufferPointer.Declaration
Swift
public init(buffer: UnsafeBufferPointer<Int8>, name: String, requiresNullTerminator: Bool = false)Parameters
bufferThe underlying buffer that contains the data.
nameThe name for the new memory buffer.
requiresNullTerminatorWhether or not the
MemoryBuffershould append a null terminator. Defaults tofalse -
Creates a
MemoryBufferby copying the data within a specifiedUnsafeBufferPointer.Declaration
Swift
public init(copyingBuffer buffer: UnsafeBufferPointer<Int8>, name: String)Parameters
bufferThe underlying buffer that contains the data.
nameThe name for the new memory buffer.
-
Creates a
MemoryBufferwith the contents of the file at the provided path.Throws
MemoryBufferErrorif there was a problem creating the buffer or reading the file.Declaration
Swift
public init(contentsOf file: String) throwsParameters
fileThe full path of the file you’re trying to read.
-
Retrieves the start address of this buffer.
Declaration
Swift
public var start: UnsafePointer<Int8> { get } -
Retrieves the size in bytes of this buffer.
Declaration
Swift
public var size: Int { get } -
Makes an iterator so this buffer can be traversed in a
forloop.Declaration
Swift
public func makeIterator() -> UnsafeBufferPointer<Int8>.Iterator
MemoryBuffer Class Reference