Click or drag to resize
gmp_libgmp_asprintf Method
Form a null-terminated string in a block of memory obtained from the current memory allocation function.

Namespace:  Math.Gmp.Native
Assembly:  Math.Gmp.Native (in Math.Gmp.Native.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public static int gmp_asprintf(
	ptr<char_ptr> pp,
	string fmt,
	params Object[] args
)

Parameters

pp
Type: Math.Gmp.Nativeptrchar_ptr
Pointer to returned, allocated string.
fmt
Type: SystemString
Format string. See Formatted Output Strings.
args
Type: SystemObject
Arguments.

Return Value

Type: Int32
The return value is the number of characters produced, excluding the null-terminator.
Remarks

The block will be the size of the string and null-terminator. The address of the block in stored to pp.

Unlike the C library asprintf, gmp_asprintf doesn’t return -1 if there’s no more memory available, it lets the current allocation function handle that.

Examples
// Create pointer to unmanaged character string pointer.
ptr<char_ptr> str = new ptr<char_ptr>();

mpz_t z = "123456";
mpq_t q = "123/456";
mpf_t f = "12345e6";
mp_limb_t m = 123456;

// Print to newly allocated unmanaged memory string.
Assert.IsTrue(gmp_lib.gmp_asprintf(str, "%Zd - %QX - %Fa - %Mo", z, q, f, m) == 42);
Assert.IsTrue(str.Value.ToString() == "123456 - 7B/1C8 - 0x2.dfd1c04p+32 - 361100");

// Release unmanaged memory.
gmp_lib.free(str.Value);
gmp_lib.mpz_clear(z);
gmp_lib.mpq_clear(q);
gmp_lib.mpf_clear(f);
See Also