GMP Native Interface for .NET
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 )
Public Shared Function gmp_asprintf ( pp As ptr(Of char_ptr), fmt As String, ParamArray args As Object() ) As Integer
public: static int gmp_asprintf( ptr<char_ptr>^ pp, String^ fmt, ... array<Object^>^ args )
static member gmp_asprintf : pp : ptr<char_ptr> * fmt : string * args : Object[] -> int
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: Int32The 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);
' Create pointer to unmanaged character string pointer. Dim str As New ptr(Of char_ptr)() Dim z As mpz_t = "123456" Dim q As mpq_t = "123/456" Dim f As mpf_t = "12345e6" Dim m As mp_limb_t = 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)
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
See Also