runtime

使用runtime完成解档归档

南楼画角 提交于 2019-11-29 00:22:23
简单的创建一个Person对象,并声明几个属性 @interface Person : NSObject<NSCoding> // 归档问题 必须遵守该协议 /** */ @property(copy,nonatomic)NSString * name; /** */ @property(assign,nonatomic)int age; @property(assign,nonatomic)int age1; @end 设置哪些属性是需要归档的 //告诉系统,归档哪些属性 - (void)encodeWithCoder:(NSCoder *)coder { //利用runtime 来归档!! unsigned int count = 0; // 拷贝一个类 的属性列表 Ivar * ivars = class_copyIvarList([Person class], &count); // 在C语言中 但凡看到了一个传递了基本数据类型的指针 一般都是在函数中 改变外面参数的值 (这个ivars 可以形象的比喻为 数组 但是又区别于数组 如当我们 做ivars[100] 有可能不会报我们常见的数组越界而返回一个null 所以你懂得) for (int i = 0; i < count; i++) { //拿出每一个Ivar Ivar ivar = ivars[i]; const

How to provide an interface to JavaCompiler when compiling a source file dynamically?

安稳与你 提交于 2019-11-28 23:56:52
I'm trying to compile and load a class at runtime, without knowing the package of the class. I do know that the class should comply with an interface, and the location of the source, (and hence the class name). I'm trying the following: /* Compiling source */ File root = new File("scripts"); File sourceFile = new File(root, "Test.java"); JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); compiler.run(null, null, null, sourceFile.getPath()); where the Test.java file looks something like import foo.Itest; public class Test implements Itest{ ... } And I get a cannot find symbol symbol

Select template argument at runtime in C++

时光怂恿深爱的人放手 提交于 2019-11-28 23:46:45
Suppose I have a set of functions and classes which are templated to use single ( float ) or double precision. Of course I could write just two pieces of bootstrap code, or mess with macros. But can I just switch template argument at runtime? No, you can't switch template arguments at runtime, since templates are instantiated by the compiler at compile-time. What you can do is have both templates derive from a common base class, always use the base class in your code, and then decide which derived class to use at runtime: class Base { ... }; template <typename T> class Foo : public Base { ...

Android how to change the application language at runtime

情到浓时终转凉″ 提交于 2019-11-28 23:14:26
I want to let the user change the language of my application using spinner (or any way). I tried many ways but they change the language of this activity not all activities, and I want to save it so when the user restart the app he will find the last choosed language. you can use this code in spinner or any way you want String languageToLoad = "en"; // your language Locale locale = new Locale(languageToLoad); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources()

Understanding the Objective-C Runtime

谁说我不能喝 提交于 2019-11-28 22:33:04
The Objective-C Runtime is one of the overlooked features of Objective-C initially when people are generally introduced to Cocoa/Objective-C. The reason for this is that while Objective-C (the language) is easy to pick up in only a couple hours, newcomers to Cocoa spend most of their time wrapping their heads around the Cocoa Framework and adjusting to how it works. However the runtime is something that everybody should at least know how it works in some detail beyond knowing that code like [target doMethodWith:var1]; gets translated into objc_msgSend(target,@selector(doMethodWith:),var1); by

Runtime详解(转)

有些话、适合烂在心里 提交于 2019-11-28 22:32:47
http://southpeak.github.io/blog/2014/10/25/objective-c-runtime-yun-xing-shi-zhi-lei-yu-dui-xiang/ http://southpeak.github.io/blog/2014/10/30/objective-c-runtime-yun-xing-shi-zhi-er-:cheng-yuan-bian-liang-yu-shu-xing/ 来源: oschina 链接: https://my.oschina.net/u/2344008/blog/539798

The Objective-C runtime

六眼飞鱼酱① 提交于 2019-11-28 22:30:30
By your _cmd This post is a write-up of a talk I gave at Alt Tech Talks: London on the Objective-C runtime. Seriously though, you should’ve been there. The Objective-C runtime? That’s the name of the library of C functions that implement the nuts and bolts of Objective-C. Objects could just be represented as C structures, and methods could just be implemented as C functions. In fact they sort of are, but with some extra capabilities. These structures and functions are wrapped in this collection of runtime functions that allows Objective-C programs to create, inspect and modify classes, objects

How to calculate memory usage of a Java program?

孤人 提交于 2019-11-28 21:28:42
If I use the Runtime class ( freeMemory() , totalMemory() , and gc() ), then it gives me memory above MB (i.e. 1,000,000 bytes). But if I run the same code on any online compiler, then they show memory used in KB (i.e. 1000 bytes). This is a huge difference. This means Runtime does not show the actual memory used by the program. I need to calculate actual memory used by the program. What is the way these online compilers use to calculate memory used by the program? First calculate the memory used before your code execution i.e. first line of your code. long beforeUsedMem=Runtime.getRuntime()

What is the difference between Version and 'Runtime Version' in .Net?

强颜欢笑 提交于 2019-11-28 21:01:55
When I open the properties window of one of the referenced dlls in my project in Visual Studio I see a Version and also a runtime version . Actually it is Rhino.Mocks library I am checking. And I see Runtime Version : v2.0.50727 Version : 3.6.0.0 What is the difference? (Does it mean I am not able to use 3.6.0.0 of the Rhino Mocks?) Adam Houldsworth Runtime is the version of the CLR (or .NET framework) the DLL needs (usually as a minimum), version is the DLL's version. So long as you have the minimum runtime installed, it should be usable. However as a general rule it is usually best to select

How to find time taken to run a Java program?

拟墨画扇 提交于 2019-11-28 20:57:30
问题 I have a Java application that I've been working on and I just realized that the program has to return a value in less than a minute, but don't know how to find or display the time taken to run the program. How to find time taken to run a program? 回答1: You can compare times using System.nanoTime() . It will return the time in nanoseconds. Returns the current value of the most precise available system timer, in nanoseconds. You could use it like this: long startTime = System.nanoTime(); //