the Fiddler's picture

Marshal.PtrToStringAnsi replacement

Project:The Open Toolkit library
Version:1.0-beta-1
Component:Code
Category:bug report
Priority:minor
Assigned:the Fiddler
Status:closed
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

Comment viewing options

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

#1

Priority:normal» minor
the Fiddler's picture

#2

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

Updated title.

the Fiddler's picture

#3

Status:open» fixed

Implemented in SVN trunk.

the Fiddler's picture

#4

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

Closing issues fixed in 1.0 beta-1.