
Marshal.PtrToStringAnsi replacement
Posted Monday, 12 January, 2009 - 14:36 by the Fiddler| Project: | The Open Toolkit library |
| Version: | 1.0-beta-1 |
| Component: | Code |
| Category: | bug report |
| Priority: | minor |
| Assigned: | the Fiddler |
| Status: | closed |
Jump to:
Description
Functions that return pointers to strings, such as GL.GetString, use wrappers that convert the returned pointer to managed strings, i.e:
[DllImport("opengl32")] static extern IntPtr glGetString(StringName name); public static string GetString(StringName name) { return Marshal.PtrToStringAnsi(glGetString(name)); }
This wrapper can be written as follows for a 5x-10x speed increase:
public static string GetString(StringName name) { unsafe { return new string((sbyte*)glGetString(name)); } }
We have to investigate if this works regardless of the current culture. If so the generator should be modified to use the second wrapper instead of the first.


Comments
#1
#2
Updated title.
#3
Implemented in SVN trunk.
#4
Closing issues fixed in 1.0 beta-1.