public static string fftw_export_wisdom_to_string() { // We cannot use the fftw_export_wisdom_to_string function here // because we have no way of releasing the returned memory. StringBuilder sb = new StringBuilder(); FftwInterop.WriteCharHandler writeChar = (c, ptr) => sb.Append((char)c); FftwInterop.fftw_export_wisdom(writeChar, IntPtr.Zero); return(sb.ToString()); }
static string GetVersion() { const string VersionPrefix = "fftw-"; const byte WhiteSpace = (byte)' '; byte[] prefix = Encoding.ASCII.GetBytes(VersionPrefix); int i = 0; StringBuilder sb = new StringBuilder(); FftwInterop.WriteCharHandler writeChar = (c, ptr) => { if (i < 0) { return; } if (i == VersionPrefix.Length) { if (c == WhiteSpace) { i = -1; } else { sb.Append((char)c); } } else if (c == prefix[i]) { i++; } else { i = 0; } }; // This is only called on initialization, so no synchronization/lock is required FftwInterop.fftw_export_wisdom(writeChar, IntPtr.Zero); return(sb.ToString()); }