typedreference

Why is TypedReference.MakeTypedReference so constrained?

情到浓时终转凉″ 提交于 2019-12-11 03:01:53
问题 I've finally understood the usage of the TypedReference.MakeTypedReference method, but why are the arguments so limited? The underlying private InternalMakeTypedReference(void* result, object target, IntPtr[] flds, RuntimeType lastFieldType) can do a lot more things than the MakeTypedReference that limits the field array to have elements and the field types to be non-primitive. I've made a sample usage code that shows the full possibility of it: private static readonly MethodInfo

Marshal.StructureToPtr without boxing

旧城冷巷雨未停 提交于 2019-12-09 19:27:41
问题 Is there a way to marshal a structure (possibly stored in a TypedReference ) to unmanaged memory without actually boxing it? The type of the structure isn't known at runtime, so I can't use the generic overload of StructureToPtr (.NET 4.5.1). I can get a MethodInfo of the StructureToPtr overload, but there doesn't seem to be a way to invoke it passing a generic reference or a TypedReference . Edit: The generic StructureToPtr still boxes the structure, so trying to invoke it is useless. 回答1: I

Marshal.StructureToPtr without boxing

一个人想着一个人 提交于 2019-12-04 17:19:37
Is there a way to marshal a structure (possibly stored in a TypedReference ) to unmanaged memory without actually boxing it? The type of the structure isn't known at runtime, so I can't use the generic overload of StructureToPtr (.NET 4.5.1). I can get a MethodInfo of the StructureToPtr overload, but there doesn't seem to be a way to invoke it passing a generic reference or a TypedReference . Edit: The generic StructureToPtr still boxes the structure, so trying to invoke it is useless. I've finally found the answer, the SafeBuffer class. It contains exactly what I wanted - structure with

Practical uses of TypedReference

血红的双手。 提交于 2019-11-29 01:07:06
Are there any practical uses of the TypedReference struct that you would actually use in real code? EDIT : The .Net framework uses them in overloads of Console.WriteLine and String.Concat which build an array from an __arglist parameter and pass it to the normal params overload. Why do these overloads exist? Eric Lippert Are there any practical uses of the TypedReference struct that you would actually use in real code? Yes. I'd use them if I needed interoperability with C-style variadic methods. Why do these overloads exist? They exist for interoperability with callers who like to use C-style

Practical uses of TypedReference

▼魔方 西西 提交于 2019-11-27 21:32:59
问题 Are there any practical uses of the TypedReference struct that you would actually use in real code? EDIT : The .Net framework uses them in overloads of Console.WriteLine and String.Concat which build an array from an __arglist parameter and pass it to the normal params overload. Why do these overloads exist? 回答1: Are there any practical uses of the TypedReference struct that you would actually use in real code? Yes. I'd use them if I needed interoperability with C-style variadic methods. Why

Why is TypedReference behind the scenes? It's so fast and safe… almost magical!

烂漫一生 提交于 2019-11-26 16:54:40
Warning: This question is a bit heretical... religious programmers always abiding by good practices, please don't read it. :) Does anyone know why the use of TypedReference is so discouraged (implicitly, by lack of documentation)? I've found great uses for it, such as when passing generic parameters through functions that shouldn't be generic (when using an object might be overkill or slow, if you need a value type), for when you need an opaque pointer, or for when you need to access an element of an array quickly, whose specs you find at runtime (using Array.InternalGetReference ). Since the

Why is TypedReference behind the scenes? It's so fast and safe… almost magical!

≯℡__Kan透↙ 提交于 2019-11-26 04:57:49
问题 Warning: This question is a bit heretical... religious programmers always abiding by good practices, please don\'t read it. :) Does anyone know why the use of TypedReference is so discouraged (implicitly, by lack of documentation)? I\'ve found great uses for it, such as when passing generic parameters through functions that shouldn\'t be generic (when using an object might be overkill or slow, if you need a value type), for when you need an opaque pointer, or for when you need to access an