Struct FastBuffer<T>
Memory buffer on stack with ability to expand and use heap memory.
Can be used for calling Windows API or building arrays.
Must be used with [SkipLocalsInit]
attribute; add it to the caller function or class.
public ref struct FastBuffer<T> where T : unmanaged
Type Parameters
Name | Description |
---|---|
T |
Examples
print.it(api.GetEnvironmentVariable("temp"));
unsafe class api : NativeApi {
[DllImport("kernel32.dll", EntryPoint = "GetEnvironmentVariableW", SetLastError = true)]
static extern int _GetEnvironmentVariable(string lpName, char* lpBuffer, int nSize);
[SkipLocalsInit]
internal static string GetEnvironmentVariable(string name) {
using FastBuffer<char> b = new();
for (; ; ) if (b.GetString(_GetEnvironmentVariable(name, b.p, b.n), out var s)) return s;
}
}
Namespace: Au.More
Assembly: Au.dll
Constructors
Name | Description |
---|---|
FastBuffer() | Allocates first buffer of default size. It is on stack (in this variable), and its length is |
FastBuffer(int) | Allocates first buffer of specified size. |
Fields
Name | Description |
---|---|
StackSize | A FastBuffer variable contains a field of this size. It is a memory buffer on stack.
It is a byte count and does not depend on T. To get count of T elements on stack: |
Properties
Name | Description |
---|---|
this[int] | Gets reference to |
n | Memory buffer length as number of elements of type T. |
p | Memory buffer pointer. |
Methods
Name | Description |
---|---|
Dispose() | Frees allocated memory if need. |
FindByteStringLength() | Finds length of |
FindStringLength() | Finds length of |
GetString(int, out string, BSFlags, string) | Gets API result as string, or allocates bigger buffer if old buffer was too small. This function can be used when T is char. |
GetStringFindLength() | Finds length of |
More(bool) | Allocates new bigger buffer of at least |
More(int, bool) | Allocates new bigger buffer of specified length. Frees old buffer if need. |
Operators
Name | Description |
---|---|
implicit operator T*(in FastBuffer<T>) | Returns memory buffer pointer (FastBuffer<T>.p). |