Mono.Posix 1.0.5000.0 2.0.0.0 4.0.0.0 This type is safe for multithreaded operations. System.Object Provides a collection of miscellaneous methods for marshaling strings, allocating memory, and interoperating with the operating system.

The UnixMarshal class consists of many members to facilitate the class, specifically for use with Unix.

The following table assigns each method to a category that describes its usage:

Category
Members
Data Transformation

Managed to unmanaged: ,

Unmanaged to managed: , ,

Error Handling
, , , , ,
Memory Management
, ,
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IntPtr `` A containing the number of bytes to allocate on the system heap. Allocates bytes from the system heap. A containing the address of bytes on the system heap, or if the memory could not be allocated.

  The "system heap" is where dynamic memory is allocated by the runtime C library, MSVCRT.DLL on Win32 and libc on Unix platforms.

  The memory allocated by this function must be freed via to avoid a memory leak.

  is a negative value.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` A containing the address of a block of memory previously returned by or . Frees the memory referenced by .

  If is , no action occurs.

  The "system heap" is where dynamic memory is allocated by the runtime C library, MSVCRT.DLL on Win32 and libc on Unix platforms.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.CLSCompliant(false)
  System.String `` A containing the error code to get the description for. Gets a description for the error code . A containing a description of the specified error code .

  If isn't a valid error number or isn't supported by the operating system, then the string "** Unknown error code: **" is returned.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String `` A containing the address of an unmanaged string in the encoding. Allocates a managed and marshals the unmanaged string into the managed string. A containing a copy of the unmanaged string , or if is .

  The input string must have a terminating null 0x00 byte.

  This method is identical to (, ).

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String `` `` A containing the address of an unmanaged string in the encoding. A specifying which encoding is in. Allocates a managed and marshals the unmanaged string into the managed string using the specified encoding. A containing a copy of the unmanaged string , or if is .

  The input string must have a terminating null. The definition of "terminating null" is fluid in this context, since the size of a terminating null depends upon the encoding specified.

  A terminating null is a single byte containing the value 0x00 if is one of the following encodings: , , , or .

  A terminating null is the value 0x0000 if is .

  Otherwise, the terminating null must consist of a sequence of (1) bytes having the value 0x00. This potentially plays havoc with multi-byte encodings, as many multi-byte encodings would only use a single byte for the terminating null, and not the maximum possible number of bytes used for encoding any character to be used for the terminating null.

  Any buffer returned by will satisfy this requirement.

  is .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String[] `` A containing a ** array which follows the ANSI C rules for the argv argument passed to main. Allocates a array and unmarshals the unmanaged string array into a managed string array. A array containing all the strings in the unmanaged string array. If is , a string array containing zero elements is returned.

  This is identical to calling (, ).

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String[] `` `` A containing the number of strings in . A containing a ** array. Allocates a array and unmarshals the unmanaged string array into a managed string array. A array containing strings from the unmanaged string array . If is , a string array containing zero elements is returned.

  This method is identical to (, , ).

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String[] `` `` A containing a ** array which follows the ANSI C rules for the argv argument passed to main. A specifying the encoding of the unmanaged strings within . Allocates a array and unmarshals the unmanaged string array into a managed string array using the specified encoding. A array containing all the strings in the unmanaged string array. If is , a string array containing zero elements is returned.

  is assumed to be a Cchar** pointer containing a terminating pointer to designate the end of the array. This follows the requirements for argv in the ANSI C main function declaration.

  `static const char* stringArray[] = { "string 1", "string 2", NULL };`

  The final null string will not be returned from this method; the above stringArray declaration would create an array containing two elements if passed through this method.

  is .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String[] `` `` `` A containing the number of strings in . A containing a ** array. A specifying the encoding of the unmanaged strings within . Allocates a array and unmarshals the unmanaged string array into a managed string array using the specified encoding. A array containing strings from the unmanaged string array . If is , a string array containing zero elements is returned.

  No validation is done to ensure that the pointers for embedded strings are valid. This could result in an access violation or corrupted strings if you're not careful. Embedded null pointers will become strings within the returned array.

  The difference between this method and is that this method doesn't require a terminating null pointer.

  is .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String `` A containing the address of an unmanaged string in the encoding. Allocates a managed and marshals the unmanaged string into the managed string using the encoding. A containing a copy of the unmanaged string , or if is .

  The input string must have a terminating null 0x00 byte.

  This is an optimized version of for the encoding.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IntPtr `` `` A containing the address of the memory block to resize. This value must either be or a value previously returned by or . A containing the number of bytes to allocate on the system heap. Changes the size of the memory block to refer to bytes of memory on the system heap.

  A containing the address of bytes on the system heap, or if the memory could not be allocated.

  If is returned, is still a valid memory address, and must still be freed.

  This function changes the size of the previously allocated memory referenced by to bytes. must have been previously allocated via or , or must be the value (in which case this method is identical to ). The contents of the memory are unchanged up to the lesser of the new and old sizes. If the new size is larger, the value of the newly allocated portion of the memory is undefined.

  The memory allocated by this function must be freed via to avoid a memory leak.

  If the requested memory cannot be allocated, is returned and the memory referenced by is valid and unchanged.

  If memory can be allocated, the memory referenced by is freed and a pointer to the newly allocated memory is returned. Note that this may be different from the value passed as .

  The "system heap" is where dynamic memory is allocated by the runtime C library, MSVCRT.DLL on Win32 and libc on Unix platforms.

  is a negative value.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean `` A containing the return value of a method from . Returns a indicating whether a system call should be retried. Returns if is -1 and returns . Otherwise, is returned.

  System calls may need to be restarted for a variety of reasons, generally explained within the system call documentation. The most typical reason is that the system call was interrupted, and the caller is expected to re-invoke the system call to complete the operation.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.CLSCompliant(false)
  System.Boolean `` `` A containing the return value of a method from . A reference to a variable which will capture the last error value. Returns a indicating whether a system call should be retried, saving the last error value for later processing. Returns if is -1 and returns , in which case will have the value . Otherwise, is returned, and will store the value from the call to .

  System calls may need to be restarted for a variety of reasons, generally explained within the system call documentation. The most typical reason is that the system call was interrupted, and the caller is expected to re-invoke the system call to complete the operation.

  This method saves the last error value returned from into the parameter.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IntPtr `` A to copy into the system heap. Allocates a copy of on the system heap in the encoding. A containing a pointer on the system heap containing the marshaled string. If is , then is returned.

  The pointer returned should be freed with to avoid a memory leak.

  This is identical to (, ).

  There was an error marshaling into the encoding. Unable to allocate enough memory for the marshaled string. []
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IntPtr `` `` A to copy into the system heap. A specifying which encoding to marshal the string into. Allocates a copy of on the system heap in the encoding. A containing a pointer on the system heap containing the marshaled string. If is , then is returned.

  The pointer returned should be freed with to avoid a memory leak.

  This is identical to (, 0, s.Length, ).

  is . There was an error marshaling into the specified encoding . Unable to allocate enough memory for the marshaled string. []
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IntPtr `` `` `` A to copy into the system heap. A containing the start index into to start marshaling. A containing the number of characters to marshal from starting at index . Allocates a copy of on the system heap in the encoding. A containing a pointer on the system heap containing the marshaled string. If is , then is returned.

  The pointer returned should be freed with to avoid a memory leak.

  This is identical to (, , , ).

  or is less than zero.

  -or-

  plus is greater than the length of .

  There was an error marshaling into the encoding. Unable to allocate enough memory for the marshaled string. []
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IntPtr `` `` `` `` A to copy into the system heap. A containing the start index into to start marshaling. A containing the number of characters to marshal from starting at index . A specifying which encoding to marshal the string into. Allocates a copy of on the system heap in the encoding. A containing a pointer on the system heap containing the marshaled string. If is , then is returned.

  The pointer returned should be freed with to avoid a memory leak.

  is .

  or is less than zero.

  -or-

  plus is greater than the length of .

  There was an error marshaling into the specified encoding . Unable to allocate enough memory for the marshaled string. []
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.CLSCompliant(false)
  System.Void `` A specifying the exception to throw. Throws an exception that best matches .

  This method translates into its closest matching exception type, and throws the exception.

  If the exception thrown is not a , then the exception's property will be set to a instance wrapping , if possible. does not have its property set, as does not provide a constructor that sets this property.

  is or . is . is or . is . is . is . is or . is . is . is one of: , , , , , . is . is not any of the above error values.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.CLSCompliant(false)
  System.Void `` `` A containing the return value of a method from . A specifying the exception to throw. Throws an exception that best matches if is -1.

  If is -1, then this method is equivalent to calling (). Otherwise, nothing is done.

  If the exception thrown is not a , then the exception's property will be set to a instance wrapping , if possible. does not have its property set, as does not provide a constructor that sets this property.

  is or . is . is or . is . is . is . is or . is . is . is one of: , , , , , . is . is not any of the above error values.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void Throws an exception that best matches the last error returned from .

  This is equivalent to calling ( ()).

  If the exception thrown is not a , then the exception's property will be set to a instance wrapping , if possible. does not have its property set, as does not provide a constructor that sets this property.

  is or . is . is or . is . is . is . is or . is . is . is one of: , , , , , . is . is not any of the above error values.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` A containing the return value of a method from . Throws an exception that best matches the last error returned from if is -1.

  If is -1, then this method is equivalent to calling ( ()). Otherwise, nothing is done.

  If the exception thrown is not a , then the exception's property will be set to a instance wrapping , if possible. does not have its property set, as does not provide a constructor that sets this property.

  is or . is . is or . is . is . is . is or . is . is . is one of: , , , , , . is . is not any of the above error values.