kvark's picture

ISized interface

Project:The Open Toolkit library
Version:all versions
Component:Code
Category:feature request
Priority:minor
Assigned:Unassigned
Status:closed
Description

It would be pretty useful to me if data structures like Vector* and Quaternion* are exposing some ISized interface that provides SizeInBytes-similar property.
Right now I'm using Marshal.SizeOf for that, because the data is hid under generics.


Comments

Comment viewing options

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

#1

Submitting the Math patch.
It's just a matter of 2 clicks to accept, if you agree on it.

AttachmentSize
OpenTK.Math_.patch13.97 KB
zahirtezcan's picture

#2

I am currently using a class like this:

public class SizeOf<T>
{
    public static readonly int Value = Marshal.Sizeof(typeof(T));
}
 
...
 
int stride = SizeOf<MyDataType>.Value;

it calls for the Marshal once and looks like the function you need. If this is a performance/design failure please let me know so I will switch to ISized interface usage.

kvark's picture

#3

Thanks, this way looks good.
I hope it works correctly :)

kvark's picture

#4

Status:open» closed

Works good :)

the Fiddler's picture

#5

Check out OpenTK.BlittableValueType and OpenTK.BlittableValueType<T>, they implement exactly this.