the Fiddler's picture

Marshal.PtrToStringAnsi replacement

Project:The Open Toolkit library
Category:bug report
Assigned:the Fiddler

Functions that return pointers to strings, such as GL.GetString, use wrappers that convert the returned pointer to managed strings, i.e:

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.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture


Priority:normal» minor
the Fiddler's picture


Title:Marshal.PtrToStringAnsi is slow and generates garbage.» Marshal.PtrToStringAnsi replacement

Updated title.

the Fiddler's picture


Status:open» fixed

Implemented in SVN trunk.

the Fiddler's picture


Version:0.9.x-dev» 1.0-beta-1
Status:fixed» closed

Closing issues fixed in 1.0 beta-1.