LowLevel

Description

static class Tinman.Core.System.LowLevel

This class provides methods for accessing low level native functions.

The following methods and properties may be used to write platform-specific code:

Public / Methods

Address​Of


[Pure]
public static method AddressOf → (3)

first in : IntPtr

Pointer to first array element.

element in : int32

The zero-based element index.

size opt : int32 = 1

The element size, in bytes.

returns → IntPtr

The pointer to the element in-th element.

Returns the address of an array element.

Copy


public static method Copy → (3)

source in : IntPtr

Pointer to source block.

target in : IntPtr

Pointer to target block.

count in : int32

[>=0]
Number of bytes to copy.

Copies a block of CPU memory.

Double​To​Long


[Pure]
public static method DoubleToLong → (1)

value in : float64

The floating point value.

returns → int64

The integer value, holding the IEEE 754 compliant bit pattern.

Interprets the given 64-bit floating point value as a 64-bit integer value.

Float​To​Int


[Pure]
public static method FloatToInt → (1)

value in : float32

The floating point value.

returns → int32

The integer value, holding the IEEE 754 compliant bit pattern.

Interprets the given 64-bit floating point value as a 64-bit integer value.

Get​Variable


public static method GetVariable → (1)

variable in : string

[not-empty]
The variable name.

returns → string

The variable value or null if not found or not allowed.

Returns the value of an environment variable.

The environment variable is retrieved from the user that is running the current process. If not found, the variable is retrieved from the current process.

Int​To​Float


[Pure]
public static method IntToFloat → (1)

value in : int32

The integer value, holding the IEEE 754 compliant bit pattern.

returns → float32

The floating point value.

Interprets the given 32-bit integer as a 32-bit floating point value.

Long​To​Double


[Pure]
public static method LongToDouble → (1)

value in : int64

The integer value, holding the IEEE 754 compliant bit pattern.

returns → float64

The floating point value.

Interprets the given 64-bit integer as a 64-bit floating point value.

Platform​Force


public static method PlatformForce → (2)

posix in : bool

The value to be returned by IsPosix.

windows in : bool

The value to be returned by IsWindows.

Forces platform detection to the given values.

This method must be called before the Tinman 3D library is initialized (see TinmanModule.Initialize), otherwise undefined behaviour may occur.

Set​System​Info


public static method SetSystemInfo → (2)

memoryTotal in : int64

[>=0]
The total amount of physical memory that is available to the process. If 0, the amount will be determined automatically.

processorCount in : int32

[>=0]
The number of (logical) processors on the system. If 0, the amount will be determined automatically.

Specifies values for MemoryTotal and ProcessorCount.

To​Ptr

2 overloads


[Pure]
public static method ToPtr1 → (1)

value in : int32

The integer value.

returns → IntPtr

The native pointer value.

Interprets the given 32-bit integer as a native pointer value.


[Pure]
public static method ToPtr2 → (1)

value in : int64

The integer value.

returns → IntPtr

The native pointer value.

Interprets the given 32-bit integer as a native pointer value.

Public / Attributes

Cpu​Total


public static attribute CpuTotal → (get)

value : int32

[0..100]
The estimated total CPU usage or 0 if not available (see remarks).

Returns the estimated total CPU usage of the system.

The returned value is intended to be used for informational purposes only.

If the CPU usage cannot be determined (for any reason), this property will return 0.

Cpu​Used


public static attribute CpuUsed → (get)

value : int32

[0..100]
The estimated process CPU usage or 0 if not available (see remarks).

Returns the estimated CPU usage of the calling process.

The returned value is intended to be used for informational purposes only.

If the CPU usage cannot be determined (for any reason), this property will return 0.

Debug


[Constant]
public static attribute Debug → (get)

value : DebugFlags

The debug flags.

Returns the debug flags of the process.

The debug flags are determined when TinmanModule.Initialize is called.

See also

LowLevel.IsDebug

Is64​Bit


[Constant]
public static attribute Is64Bit → (get)

value : bool

true if the underlying environment is 64-bit, false if not.

Checks if the underlying environment is 64-bit.

Is​Debug


[Constant]
public static attribute IsDebug → (get)

value : bool

true if Debug contains any DebugFlags.Debug bit,
false if it contains none of them.

Checks if the process exhibits DEBUG or DEBUGGER behaviour (as indicated by object.ToString of TinmanError).

Is​Posix


[Constant]
public static attribute IsPosix → (get)

value : bool

true : POSIX.1-2008 (and some optional GNU extensions),
false : if running under some other platform.

Is the calling process running under an OS that is compliant to POSIX?

The value of this flag may be used to decide at runtime which native system API to use, for example when doing CLR P/Invoke or when loading shared libraries.

The value of this flag is determined at runtime for C# and at compile-time for C++. So the same C# assembly may exhibit different behaviour between POSIX and Windows.

Is​Windows


[Constant]
public static attribute IsWindows → (get)

value : bool

true : Windows API (7 or newer),
false : if running under some other platform.

Running under a Windows OS?

The value of this flag may be used to decide at runtime which native system API to use, for example when doing CLR P/Invoke or when loading shared libraries.

The value of this flag is determined at runtime for C# and at compile-time for C++. So the same C# assembly may exhibit different behaviour between POSIX and Windows.

Memory​Total


[Constant]
public static attribute MemoryTotal → (get)

value : int64

[>=0]
The total amount of available memory, in bytes.

Returns the total amount of physical memory that is available to the process.

If the memory amount cannot be determined (for any reason), this property will return 0. The SetSystemInfo method can be used to manually specify the amount of available physical memory.

Memory​Used


public static attribute MemoryUsed → (get)

value : int64

[>=0]
The estimated amount of used physical memory, in bytes.

Returns the estimated amount of physical memory that is currently being used by the process.

The returned value is intended to be used for informational purposes only. If the memory amount cannot be determined (for any reason), this property will return 0.

Platform​Name


[Constant]
public static attribute PlatformName → (get)

value : string

[not-null]
The platform name.

Returns the human-readable name of the underlying platform.

The returned value is only intended for reporting, logging and debugging.

Processor​Count


[Constant]
public static attribute ProcessorCount → (get)

value : int32

[>=1]
The number of processors.

Returns the number of (logical) processors on the system.

This value does not necessarily represent physical CPU cores. Instead, it is meant to be a guide for determining how many threads to run in parallel at a given point in time.

Programming​Language​Name


[Constant]
public static attribute ProgrammingLanguageName → (get)

value : string

[not-null]
The programming language name.

Returns the human-readable name of the underlying programming language.

System​Time​String


public static attribute SystemTimeString → (get)

value : string

[not-null]
The UTC system time string.

Returns the UTC system time in the following format: yyyy-MM-dd HH:mm:ss (for example 2014-01-31 15:56:30).

Tick​Count


public static attribute TickCount → (get)

value : int32

The current system tick, in milliseconds.

Returns the system tick count.

Upon initialization, the tick count starts at zero and will change sign every ~12 days. To avoid bugs due to wrap around, please note the following:

int timeout = 60000;

// Never (!) do this:
int time = LowLevel.TickCount + timeout;
while (LowLevel.TickCount < time)
{
  // Timeout detection will fail after wrap around!
}

// Instead, do this:
int time = LowLevel.TickCount;
while (LowLevel.TickCount - time < timeout)
{
  // Integer arithmetic properly handles wrap around.
}

System tick count values should not be used across thread boundaries.

Tick​Count​Precise


public static attribute TickCountPrecise → (get)

value : int64

The current system tick, in microseconds.

Returns the system tick count.

Upon initialization, the tick count starts at zero and will change sign every ~150,000 years. System tick count values should not be used across thread boundaries.