View on GitHub

Buffer Class

Abstracts the NativeBuffer and the ClrBuffer.

Syntax

public abstract class Buffer : IDisposable

Remarks

  • This class should be subclassed only with caution, it allows to change the behaviour of buffer allocations, this functionality should be used only by people who know exactly what they are doing.
  • In order to achieve faster performance, the buffer should be allocated immediately with a decent size, so the renderer won't have to grow the buffer.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Members

See Also: Inherited members from object.

Protected Constructors

Allocates a new buffer or reuses an existing one.

Public Fields

static readonly
DefaultUnitSize int . The default unit size.

Public Properties

[read-only]
AllocatedSize IntPtr . The allocated size of the buffer.
[read-only]
Data IntPtr . Buffer allocation pointer.
Encoding System.Text.Encoding . Default encoding to use for when serializing between strings and the buffer.
NativeHandle IntPtr . The native buffer handle which is used by the sundown library.
Size IntPtr . The currently used size of the buffer.
[read-only]
UnitSize IntPtr . The unit size of the particular buffer.

Public Methods

static
Create () : Buffer
Creates a buffer using the default buffer implementation.
static
Create (int) : Buffer
Creates a buffer using the default buffer implementation.
static
Create (long) : Buffer
Creates a buffer using the default buffer implementation.
static
Create (IntPtr) : Buffer
Creates a buffer using the default buffer implementation.
Dispose ()
Releases the allocated buffer.
Finalize ()
Documentation for this section has not yet been entered.
static
From (IntPtr) : Buffer
Creates an instance of the default buffer implementation from a pointer pointing to a buf handle.
GetBufferStream () : BufferStream
Wraps the current Buffer in a BufferStream.
GetBytes () : byte[]
Copies the content of the buffer into a newly allocated clr array.
GetStream () : System.IO.Stream
Creates an UnmanagedStream.
Grow (int)
Grow the buffer size.
Grow (long)
Grow the buffer size.
Grow (IntPtr)
Grow the buffer size.
Put (Buffer)
Documentation for this section has not yet been entered.
Put (byte)
Documentation for this section has not yet been entered.
Put (byte[])
Documentation for this section has not yet been entered.
Put (string)
Documentation for this section has not yet been entered.
Put (byte[], int)
Documentation for this section has not yet been entered.
Put (byte[], long)
Documentation for this section has not yet been entered.
Put (byte[], IntPtr)
Documentation for this section has not yet been entered.
Put (IntPtr, int)
Documentation for this section has not yet been entered.
Put (IntPtr, long)
Documentation for this section has not yet been entered.
Put (IntPtr, IntPtr)
Documentation for this section has not yet been entered.
Put (string, params object[])
Documentation for this section has not yet been entered.
Put (System.Text.Encoding, string)
Documentation for this section has not yet been entered.
Put (byte[], int, int)
Documentation for this section has not yet been entered.
Put (byte[], long, long)
Documentation for this section has not yet been entered.
Put (byte[], IntPtr, IntPtr)
Documentation for this section has not yet been entered.
Put (System.Text.Encoding, string, params object[])
Documentation for this section has not yet been entered.
Reset ()
Clears the buffer.
Slurp (int)
Removes a given number of bytes from the head of the buffer.
Slurp (long)
Removes a given number of bytes from the head of the buffer.
Slurp (IntPtr)
Removes a given number of bytes from the head of the buffer.

Protected Methods

abstract
Alloc (IntPtr)
Allocates the NativeHandle.
Dispose (bool)
The Dispose(bool) pattern.

Member Details

Buffer Constructor

Allocates a new buffer or reuses an existing one.

Syntax

protected Buffer (IntPtr size, bool alloc)

Parameters

size
Allocates a buffer of the size saved in the variable if the second argument alloc is true. If alloc is false, it will just use the value inside size as a pointer to the allocated buffer.
alloc
Determines how to treat the first argument IntPtr size of the constructor. If alloc is true, it will allocate a new buffer with the size saved in the 'IntPtr size' argument, if false, it will use the value in size as a pointer to the buffer.

Remarks

This class is a wrapper of the buf functionality provided sundown (a collection of methods dealing with a buffer struct). The class is unsafe, in the sense that it uses pointer aritmethic and c functions.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Alloc Method

Allocates the NativeHandle.

Syntax

protected abstract void Alloc (IntPtr size)

Parameters

size
The size of the allocated buffer.

Remarks

bufnewcb should be called from the sundown library in order to use custom allocators.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

AllocatedSize Property

The allocated size of the buffer.

Syntax

public IntPtr AllocatedSize { get; }

Value

The size of the allocated buffer.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Create Method

Creates a buffer using the default buffer implementation.

Syntax

public static Buffer Create ()

Returns

A new instance of the default buffer implementation.

Remarks

Creates a buffer with the size of DefaultUnitSize(1024), which can lead to suboptimal behaviour, if the input is know to be bigger.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Create Method

Creates a buffer using the default buffer implementation.

Syntax

public static Buffer Create (int size)

Parameters

size
The initial size of the buffer.

Returns

A new instance of the default buffer implementation.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Create Method

Creates a buffer using the default buffer implementation.

Syntax

public static Buffer Create (long size)

Parameters

size
The initial size of the buffer.

Returns

A new instance of the default buffer implementation.

Remarks

Using values greater than 32bit on 32bit machines will result in errorneous program behaviour.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Create Method

Creates a buffer using the default buffer implementation.

Syntax

public static Buffer Create (IntPtr size)

Parameters

size
The initial size of the buffer.

Returns

A new instance of the default buffer implementation.

Remarks

Using values greater than 32bit on 32bit machines will result in errorneous program behaviour.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Data Property

Buffer allocation pointer.

Syntax

public IntPtr Data { get; }

Value

A pointer to the allocated buffer.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

DefaultUnitSize Field

The default unit size.

Syntax

public static readonly int DefaultUnitSize

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Dispose Method

Releases the allocated buffer.

Syntax

public void Dispose ()

Remarks

Using this on NativeBuffer will release the allocated memory immediately, while on ClrBuffer it will just release the pinhandle and wait for the byte array to be collected by the GC.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Dispose Method

The Dispose(bool) pattern.

Syntax

protected virtual void Dispose (bool disposing)

Parameters

disposing
true if the user called Dispose, false if the garbage collector initiated the dispose method.

Remarks

Override this in your sublcasses if you want to have specific release behaviour.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Encoding Property

Default encoding to use for when serializing between strings and the buffer.

Syntax

public System.Text.Encoding Encoding { get; set; }

Value

Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Finalize Method

Documentation for this section has not yet been entered.

Syntax

void Finalize ()

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

From Method

Creates an instance of the default buffer implementation from a pointer pointing to a buf handle.

Syntax

public static Buffer From (IntPtr ptr)

Parameters

ptr
Pointer pointing to the buf handle.

Returns

A new instance of the default buffer implementation.

Remarks

Don't cross over ClrBuffer buf handles and NativeBuffer handles, because the allocated memory is allocated by GCHandle/byte[] and malloc accordingly.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

GetBufferStream Method

Wraps the current Buffer in a BufferStream.

Syntax

public BufferStream GetBufferStream ()

Returns

A BufferStream which wraps the current Buffer.

Remarks

The BufferStream let's you only write.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

GetBytes Method

Copies the content of the buffer into a newly allocated clr array.

Syntax

public byte[] GetBytes ()

Returns

A CLR byte array containing all the information of the buffer.

Remarks

The size is equal to the content size and not the buffer size. The entire content of the buffer gets copied and not just reused.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

GetStream Method

Creates an UnmanagedStream.

Syntax

public System.IO.Stream GetStream ()

Returns

An UnmanagedStream pointing to the allocated buffer memory.

Remarks

If you call this method and then call Grow on the buffer, the pointer to which the UnamangedStream is pointing might become invalid. Always drop the last Stream you got with this function if you are doing operations on the buffer which might increase the buffer(resize/realloc the memory).

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Grow Method

Grow the buffer size.

Syntax

public void Grow (int size)

Parameters

size
The amount of bytes which to grow.

Remarks

Growing passed 16MB will result in OutOfMemoryException. This is a sundown limitation.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Grow Method

Grow the buffer size.

Syntax

public void Grow (long size)

Parameters

size
The amount of bytes which to grow.

Remarks

Growing passed 16MB will result in OutOfMemoryException. This is a sundown limitation.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Grow Method

Grow the buffer size.

Syntax

public void Grow (IntPtr size)

Parameters

size
The amount of bytes which to grow.

Remarks

Growing passed 16MB will result in OutOfMemoryException. This is a sundown limitation.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

NativeHandle Property

The native buffer handle which is used by the sundown library.

Syntax

public IntPtr NativeHandle { get; protected set; }

Value

Pointer to the native buffer handle.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Put Method

Documentation for this section has not yet been entered.

Syntax

public void Put (Buffer buffer)

Parameters

buffer
Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Put Method

Documentation for this section has not yet been entered.

Syntax

public void Put (byte c)

Parameters

c
Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Put Method

Documentation for this section has not yet been entered.

Syntax

public void Put (byte[] bytes)

Parameters

bytes
Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Put Method

Documentation for this section has not yet been entered.

Syntax

public void Put (string str)

Parameters

str
Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Put Method

Documentation for this section has not yet been entered.

Syntax

public void Put (byte[] bytes, int size)

Parameters

bytes
Documentation for this section has not yet been entered.
size
Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Put Method

Documentation for this section has not yet been entered.

Syntax

public void Put (byte[] bytes, long size)

Parameters

bytes
Documentation for this section has not yet been entered.
size
Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Put Method

Documentation for this section has not yet been entered.

Syntax

public void Put (byte[] bytes, IntPtr size)

Parameters

bytes
Documentation for this section has not yet been entered.
size
Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Put Method

Documentation for this section has not yet been entered.

Syntax

public void Put (IntPtr data, int size)

Parameters

data
Documentation for this section has not yet been entered.
size
Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Put Method

Documentation for this section has not yet been entered.

Syntax

public void Put (IntPtr data, long size)

Parameters

data
Documentation for this section has not yet been entered.
size
Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Put Method

Documentation for this section has not yet been entered.

Syntax

public void Put (IntPtr data, IntPtr size)

Parameters

data
Documentation for this section has not yet been entered.
size
Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Put Method

Documentation for this section has not yet been entered.

Syntax

public void Put (string str, params object[] param)

Parameters

str
Documentation for this section has not yet been entered.
param
Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Put Method

Documentation for this section has not yet been entered.

Syntax

public void Put (System.Text.Encoding encoding, string str)

Parameters

encoding
Documentation for this section has not yet been entered.
str
Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Put Method

Documentation for this section has not yet been entered.

Syntax

public void Put (byte[] bytes, int offset, int count)

Parameters

bytes
Documentation for this section has not yet been entered.
offset
Documentation for this section has not yet been entered.
count
Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Put Method

Documentation for this section has not yet been entered.

Syntax

public void Put (byte[] bytes, long offset, long count)

Parameters

bytes
Documentation for this section has not yet been entered.
offset
Documentation for this section has not yet been entered.
count
Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Put Method

Documentation for this section has not yet been entered.

Syntax

public void Put (byte[] bytes, IntPtr offset, IntPtr count)

Parameters

bytes
Documentation for this section has not yet been entered.
offset
Documentation for this section has not yet been entered.
count
Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Put Method

Documentation for this section has not yet been entered.

Syntax

public void Put (System.Text.Encoding encoding, string str, params object[] param)

Parameters

encoding
Documentation for this section has not yet been entered.
str
Documentation for this section has not yet been entered.
param
Documentation for this section has not yet been entered.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Reset Method

Clears the buffer.

Syntax

public void Reset ()

Remarks

Doesn't release the memory, it only sets the seek pointer to 0.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Size Property

The currently used size of the buffer.

Syntax

public IntPtr Size { get; set; }

Value

Documentation for this section has not yet been entered.

Remarks

This returns how much content the buffer contains.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Slurp Method

Removes a given number of bytes from the head of the buffer.

Syntax

public void Slurp (int size)

Parameters

size
Number of bytes to remove.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Slurp Method

Removes a given number of bytes from the head of the buffer.

Syntax

public void Slurp (long size)

Parameters

size
Number of bytes to remove.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

Slurp Method

Removes a given number of bytes from the head of the buffer.

Syntax

public void Slurp (IntPtr size)

Parameters

size
Number of bytes to remove.

Remarks

Documentation for this section has not yet been entered.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0

UnitSize Property

The unit size of the particular buffer.

Syntax

public IntPtr UnitSize { get; }

Value

Documentation for this section has not yet been entered.

Remarks

The bigger the default unit size is the more memory is allocated when growing the buffer when the size is not sufficient to hold the entire content, but less allocations are needed. The best way is to allocate immediately a sufficiently big enough buffer.

Requirements

Namespace: Sundown
Assembly: SundownNet (in SundownNet.dll)
Assembly Versions: 1.15.12.0