linkage

扎心一问:NIO 和 IO 到底有什么区别?

自作多情 提交于 2020-03-15 12:30:59
前言 最近在面试过程中有被问到,在Java反射中Class.forName()加载类和使用ClassLoader加载类的区别。当时没有想出来后来自己研究了一下就写下来记录一下。 解释 在java中Class.forName()和ClassLoader都可以对类进行加载。ClassLoader就是遵循双亲委派模型最终调用启动类加载器的类加载器,实现的功能是“通过一个类的全限定名来获取描述此类的二进制字节流”,获取到二进制流后放到JVM中。Class.forName()方法实际上也是调用的CLassLoader来实现的。 Class.forName(String className);这个方法的源码是 @CallerSensitive public static Class<?> forName(String className) throws ClassNotFoundException { Class<?> caller = Reflection.getCallerClass(); return forName0(className, true, ClassLoader.getClassLoader(caller), caller); } 最后调用的方法是forName0这个方法,在这个forName0方法中的第二个参数被默认设置为了true,这个参数代表是否对加载的类进行初始化

What is the intention of ODR?

非 Y 不嫁゛ 提交于 2020-03-14 05:23:15
问题 I do understand what ODR says, but I don't understand what it tries to achieve. I see two consequences of violating it - user will get syntax error, which is totally fine. And also there may be some fatal errors, and again the user would be the only one who's guilty. As example of violating ODR and getting some fatal error I imagine like this: a.cpp struct A { int a; double b; }; void f(A a) { std::cout << a.a << " " << a.b << std::endl; } main.cpp struct A { int a; int b; }; void f(A a); int

What is the intention of ODR?

泄露秘密 提交于 2020-03-14 05:20:06
问题 I do understand what ODR says, but I don't understand what it tries to achieve. I see two consequences of violating it - user will get syntax error, which is totally fine. And also there may be some fatal errors, and again the user would be the only one who's guilty. As example of violating ODR and getting some fatal error I imagine like this: a.cpp struct A { int a; double b; }; void f(A a) { std::cout << a.a << " " << a.b << std::endl; } main.cpp struct A { int a; int b; }; void f(A a); int

Cocoapods 1.9.0 更新日志

谁说我不能喝 提交于 2020-03-09 18:57:07
CocoaPods 1.9 现在支持 “XCFrameworks”, “podspec支持基于配置的依赖”, “指定 schemes 的代码覆盖率”, “use_frameworks link自定义” XCFramework Support 推荐指数:*** 随着Xcode11,苹果引入的新的Bundle格.XCFramework. 这种支持多个不同的架构和平台类型的.framework捆绑到一个结构里面。 二进制依赖项也需要XCFrameworks来支持macOS Catalina中引入的新的Catalyst平台。 用法 Pod::Spec.new do |s| s.name = 'ToastLib' s.version = '1.0.0' # ...rest of attributes here s.vendored_frameworks = 'ButterLib.xcframework' end 如何创建xcframework参考视频 Configuration-based dependencies for Podspecs 推荐指数:** Podspecs也指出基于配置的依赖了 用法 Podfile修改 target 'BananaApp' do pod 'Toast', :configurations => ['Debug'] end Podspec修改 Pod:

ZhaoWei-2020-01-16

回眸只為那壹抹淺笑 提交于 2020-02-27 03:48:07
ZooKeeper ZooKeeper 的设计目标是将那些复杂且容易出错的分布式一致性服务封装起来,构成一个高效可靠的原语集,并以一系列简单易用的接口提供给用户使用。 ZooKeeper 是一个典型的分布式数据一致性解决方案,分布式应用程序可以基于 ZooKeeper 实现诸如数据发布/订阅、负载均衡、命名服务、分布式协调/通知、集群管理、Master 选举、分布式锁和分布式队列等功能。 Zookeeper 一个最常用的使用场景就是用于担任服务生产者和服务消费者的注册中心。 服务生产者将自己提供的服务注册到Zookeeper中心,服务的消费者在进行服务调用的时候先到Zookeeper中查找服务,获取到服务生产者的详细信息之后,再去调用服务生产者的内容与数据。 ● ZooKeeper 本身就是一个分布式程序(只要半数以上节点存活,ZooKeeper 就能正常服务)。 ● 为了保证高可用,最好是以集群形态来部署 ZooKeeper,这样只要集群中大部分机器是可用的(能够容忍一定的机器故障),那么 ZooKeeper 本身仍然是可用的。 ● ZooKeeper 将数据保存在内存中,这也就保证了 高吞吐量和低延迟 (但是内存限制了能够存储的容量不太大,此限制也是保持znode中存储的数据量较小的进一步原因)。 ● ZooKeeper 是高性能的。 在“读”多于“写”的应用程序中尤其地高性能

Mixing C and C++ global variable

做~自己de王妃 提交于 2020-02-02 05:25:06
问题 On my project, we have a header file that looks akin to this: typedef struct MyStruct { int x; } MyStruct; extern "C" MyStruct my_struct; Previously, it was only included in C++ source files. Now, I have need to include it in C files. So, I do the following: typedef struct MyStruct { int x; } MyStruct; #ifdef __cplusplus extern "C" MyStruct my_struct; #else MyStruct my_struct; #endif I understand that extern "C" will declare the my_struct global variable to be of C-linkage, but does this then

What happens when non-static function declaration follows static function declaration?

我是研究僧i 提交于 2020-01-29 10:14:22
问题 The following compiles: static int foo() { return 1; } int foo(); But, will it always compile? Is the behavior in this case well defined? And what does it means when a non-static prototype follows a static declaration? 回答1: Yes it will compile and behavior is well defined. Since foo is declared static earlier than int foo(); 1 , foo has internal linkage. C11: 6.2.2 Linkages of identifiers (p4): For an identifier declared with the storage-class specifier extern in a scope in which a prior

Understanding static variables declaration/initialization in C

谁说我不能喝 提交于 2020-01-11 09:56:05
问题 I have only one file in my project called test.c; the code below does not compile if I do not define "TRUE". I use vc. I just want to understand the behavior. Please throw some light on this aspect. #ifdef TRUE static int a; static int a = 1; #else static int a = 1; static int a; #endif int main (void) { printf("%d\n", a); return 0; } ----------------------- #ifdef TRUE // both ok int a; int a = 1; #else // both ok int a = 1; int a; #endif int main (void) { printf("%d\n", a); return 0; } 回答1:

Multiple definitions error in C++

泪湿孤枕 提交于 2020-01-06 23:49:16
问题 I'm writing a C++ program where each file has it's own set of global variable declarations. Most of these files make use of global variables that were defined in the other files using extern. Here's an example similar to my program: Main.cpp #include "stdafx.h" #include <iostream> #include "Other_File.cpp" int var1; int var2; int main() { var1 = 1; var2 = 2; otherFunction(); var4 = 4; // From Other_File.cpp std::cout << var1 << " " << var2 << " " << var3 << " " << var4 << std::endl; return(0)

C++ Standard regarding external linkage and calling conventions

浪子不回头ぞ 提交于 2020-01-06 07:46:05
问题 I've read the last C++11 draft (n3337 - is it the last one?), and I got a question for a possible implementation I've been working on. Let's say we have this code: extern "Objective C" { class Object { public: static Object *alloc(); Object *init(); }; }; Then calling Object *x = Object::alloc()->init(); The question is that I didn't understand if it is allowed for the compiler to control the calling convention of extern "X" blocks: the idea would be to "translate" the calls to objc_msgSend