runtime

Calling a generic function with a type parameter determined at runtime

耗尽温柔 提交于 2019-11-30 15:26:44
问题 I have a question involving calling a class's generic method with a type parameter that is known at runtime. In specific, the code looks like so: FieldInfo[] dataFields = this.GetType().GetFields( BindingFlags.Public | BindingFlags.Instance ); // data is just a byte array used internally in DataStream DataStream ds = new DataStream( data ); foreach ( FieldInfo field in dataFields ) { Type fieldType = field.FieldType; // I want to call this method and pass in the type parameter specified by

sizeof(value) vs sizeof(type)?

Deadly 提交于 2019-11-30 15:21:25
Considering : double data; double array[10]; std::vector<int> vec(4, 100); MyClass myclass; Is there a difference between : sizeof(double); sizeof(double[10]); sizeof(std::vector<int>); sizeof(MyClass); and sizeof(data); sizeof(array); sizeof(vec); sizeof(myclass); Are the two syntaxes different or strictly equivalent ? Are all of them evaluated at compile-time ? If not, which one is evaluated at run-time ? The only differences are in syntax and convenience. Syntactically, you're allowed to leave out the parentheses in one case, but not the other: double d; sizeof(double); // compiles sizeof(d

Create type “MyClass : OtherClass<MyClass> { }” at runtime?

偶尔善良 提交于 2019-11-30 14:59:04
问题 Is it possible in C# to create a type at runtime that inherits from a generic class where the template parameter for the base class is the current class being constructed? This will compile fine: // I have this class: public class OtherClass<T> where T : OtherClass<T> { } // I want to create this at runtime: public class MyClass : OtherClass<MyClass> { } but I'm not sure how to create the MyClass using System.Reflection.Emit.ModuleBuilder.TypeBuilder : AssemblyName asn = new AssemblyName(

How can I make a python script change itself?

坚强是说给别人听的谎言 提交于 2019-11-30 14:58:43
问题 How can I make a python script change itself? To boil it down, I would like to have a python script ( run.py )like this a = 0 b = 1 print a + b # do something here such that the first line of this script reads a = 1 Such that the next time the script is run it would look like a = 1 b = 1 print a + b # do something here such that the first line of this script reads a = 2 Is this in any way possible? The script might use external resources; however, everything should work by just running the

Why are Runtime Exceptions “unchecked” in Java?

旧街凉风 提交于 2019-11-30 14:33:37
Why does it make sense to have Runtime Exceptions UnChecked (as opposed to if they were Checked )? If you didn't you would have to have try/catch blocks every time you accessed an array element, did a division operation and many other common scenarios. To put it another way, imagine this code: Map map = ... int i = ... (int[])map.get("foo")[3] = 2334 / i; would have to check for ClassCastException , ArrayIndexOutofBoundsException , ArithmeticException , UnsupportedOperationException and NullPointerException just off the top of my head. With Java the issue isn't unchecked exceptions. Checked

Hyperledger fabric性能测试及分析

旧城冷巷雨未停 提交于 2019-11-30 14:03:05
1 Go语言性能测试 写性能测试在Go语言中是很便捷的,go自带的标准工具链就有完善的支持。 1.1 benchmark 写benchmark测试有如下约定: benchmark也是测试,因此也是以 _test.go 结尾的文件; 需要 import testing ; 测试方法以 Benchmark 开始,并且拥有一个 *testing.B 参数。 *testing.B 参数提供了大多数和 *testing.T 类似的方法,同时也额外增加了一些性能测试相关的方法。此外,还提供了一个整型成员 N ,用来指定被检测操作的执行次数。 举个例子,下边是一个连接字符串的操作: bench_test.go : package main import "testing" import "strings" func BenchmarkStringJoin1(b *testing.B) { input := [] string { "Hello" , "World" } for i := 0 ; i < b.N; i++ { result := strings.Join(input, " " ) if result != "Hello World" { b.Error( "Unexpected result: " + result) } } } 然后执行benchmark测试: $ go test

Change layout while orientation change at runtime in a fragment without recreating the view

狂风中的少年 提交于 2019-11-30 13:58:51
I try to develop a first app that download images from the net and show them in a gridview. The gridview is a fragment of a main Activity. The download process is made with an AsyncTask in the onCreate Function. In order not to download again the images while changing orientation, i set the android:configChanges="orientation|screenSize" in the Android Manifest. Then the onCreate function is only call once and everything's good ... except that i've got to make a few changes in the layout for the gridview fragment in landscape mode. So i created 2 layout sheets : fragment_library.xml and

How can I make a python script change itself?

有些话、适合烂在心里 提交于 2019-11-30 13:55:04
How can I make a python script change itself? To boil it down, I would like to have a python script ( run.py )like this a = 0 b = 1 print a + b # do something here such that the first line of this script reads a = 1 Such that the next time the script is run it would look like a = 1 b = 1 print a + b # do something here such that the first line of this script reads a = 2 Is this in any way possible? The script might use external resources; however, everything should work by just running the one run.py -file. EDIT: It may not have been clear enough, but the script should update itself, not any

Is there Dart VM available?

这一生的挚爱 提交于 2019-11-30 13:48:41
问题 Just read news that Google had announced an early preview of the new web programming language Dart. The documentation on the dartlang.org states: You will be able to run Dart code in several ways: Translate Dart code to JavaScript that can run in any modern browser: Chrome, Safari 5+, and Firefox 4+ (more browser support coming shortly). Execute Dart code directly in a VM on the server side Use Dartboard to write, modify, and execute small Dart programs within any browser window And I'm

Create type “MyClass : OtherClass<MyClass> { }” at runtime?

删除回忆录丶 提交于 2019-11-30 13:09:07
Is it possible in C# to create a type at runtime that inherits from a generic class where the template parameter for the base class is the current class being constructed? This will compile fine: // I have this class: public class OtherClass<T> where T : OtherClass<T> { } // I want to create this at runtime: public class MyClass : OtherClass<MyClass> { } but I'm not sure how to create the MyClass using System.Reflection.Emit.ModuleBuilder.TypeBuilder : AssemblyName asn = new AssemblyName("test.dll"); AssemblyBuilder asb = AppDomain.CurrentDomain.DefineDynamicAssembly( asn,