Mono Class Library: Mono.Unix.Native.Stdlib Overview | Members

Mono.Unix.Native.Stdlib.malloc Method

Allocate memory. [Edit]

[System.CLSCompliant(false)]
public static IntPtr malloc (ulong size)

Parameters

size
Amount of memory to allocate. [Edit]

Returns

The malloc() function returns a pointer to the allocated memory if successful; otherwise a IntPtr.Zero pointer is returned and Stdlib.GetLastError returns Errno.ENOMEM. [Edit]

Remarks

The malloc() function allocates size bytes of memory. The allocated space is suitably aligned (after possible pointer coercion) for storage of any type of object. If the space is at least pagesize bytes in length (see Syscall.getpagesize(3)), the returned memory will be page boundary aligned as well. If malloc() fails, IntPtr.Zero is returned.

You should Stdlib.free the return value to avoid a memory leak.

Note that malloc() does NOT normally initialize the returned memory to zero bytes.

[Edit]

Requirements

Namespace: Mono.Unix.Native
Assembly: Mono.Posix (in Mono.Posix.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0