这两天天气凉了,苏州这边连续好几天都是淅淅沥沥的下着小雨,今天天气还稍微好点。前两天早上起来突然就感冒了,当天就用了一卷纸,好在年轻扛得住,第二天就跟没事人似的。在这里提醒大家一下,天气凉了,睡凉席的可以收起来了,体质不太好的,也要适当加点衣服。

本来是想接着看源码的,早上起来又把Emitter鼓捣了一下,跟大家说说。

emitter.hpp是可以从源码中剥离出来的,只要去除里面的libuv的东西就行了。Emitter其实就是实现的即时回调,没有异步事件处理的功能。但是我们有时候是需要用并发来提高处理速度的,于是我就把Emitter稍微改造了一下,先上代码:

  1. #pragma once
  2.  
  3. #include <type_traits>
  4. #include <functional>
  5. #include <algorithm>
  6. #include <utility>
  7. #include <cstddef>
  8. #include <vector>
  9. #include <memory>
  10. #include <list>
  11. #include <queue>
  12. #include <thread>
  13. #include <mutex>
  14. #include <condition_variable>
  15. #include <chrono>
  16.  
  17. template<typename E>
  18. using event_ptr = std::unique_ptr<E>;
  19.  
  20. template<typename E, typename... Args>
  21. event_ptr<E> make_event(Args&&... args) {
  22. return std::make_unique<E>(std::forward<Args>(args)...);
  23. }
  24.  
  25. /**
  26. * @brief Event emitter base class.
  27. */
  28. template<typename T>
  29. class Emitter : public std::enable_shared_from_this<T> {
  30. struct BaseHandler {
  31. virtual ~BaseHandler() noexcept = default;
  32. virtual bool empty() const noexcept = ;
  33. virtual void clear() noexcept = ;
  34. virtual void join() noexcept = ;
  35. virtual void exit() noexcept = ;
  36. };
  37.  
  38. template<typename E>
  39. struct Handler final: BaseHandler {
  40. using Listener = std::function<void(E &, std::shared_ptr<T>&)>;
  41. using Element = std::pair<bool, Listener>;
  42. using ListenerList = std::list<Element>;
  43. using Connection = typename ListenerList::iterator;
  44.  
  45. bool empty() const noexcept override {
  46. auto pred = [](auto &&element){ return element.first; };
  47.  
  48. return std::all_of(onceL.cbegin(), onceL.cend(), pred) &&
  49. std::all_of(onL.cbegin(), onL.cend(), pred);
  50. }
  51.  
  52. void clear() noexcept override {
  53. if(!publishing.try_lock()) {
  54. auto func = [](auto &&element){ element.first = true; };
  55. std::for_each(onceL.begin(), onceL.end(), func);
  56. std::for_each(onL.begin(), onL.end(), func);
  57. } else {
  58. onceL.clear();
  59. onL.clear();
  60. }
  61. publishing.unlock();
  62. }
  63.  
  64. Connection once(Listener f) {
  65. return onceL.emplace(onceL.cend(), false, std::move(f));
  66. }
  67.  
  68. Connection on(Listener f) {
  69. return onL.emplace(onL.cend(), false, std::move(f));
  70. }
  71.  
  72. void erase(Connection conn) noexcept {
  73. conn->first = true;
  74.  
  75. if(publishing.try_lock()) {
  76. auto pred = [](auto &&element){ return element.first; };
  77. onceL.remove_if(pred);
  78. onL.remove_if(pred);
  79. }
  80. publishing.unlock();
  81. }
  82.  
  83. void run(E event, std::shared_ptr<T> ptr) {
  84. ListenerList currentL;
  85. onceL.swap(currentL);
  86.  
  87. auto func = [&event, &ptr](auto &&element) {
  88. return element.first ? void() : element.second(event, ptr);
  89. };
  90.  
  91. publishing.lock();
  92.  
  93. std::for_each(onL.rbegin(), onL.rend(), func);
  94. std::for_each(currentL.rbegin(), currentL.rend(), func);
  95.  
  96. publishing.unlock();
  97.  
  98. onL.remove_if([](auto &&element){ return element.first; });
  99. }
  100.  
  101. void thread_fun(std::shared_ptr<T> ptr)
  102. {
  103. while(true) {
  104. std::unique_lock<std::mutex> lk(emutex);
  105. econd.wait_for(lk, std::chrono::milliseconds(), [this](){return !events.empty();});
  106.  
  107. if(events.size() > ) {
  108. E event = std::move(events.front());
  109. events.pop();
  110. run(std::move(event), std::move(ptr));
  111. } else {
  112. break;
  113. }
  114. }
  115. }
  116.  
  117. void publish(E event, std::shared_ptr<T> ptr, bool asyn) {
  118. if(asyn) {
  119. {
  120. std::lock_guard<std::mutex> lk(emutex);
  121. events.push(std::move(event));
  122. }
  123. econd.notify_all();
  124.  
  125. if(!ethread.joinable()) {
  126. ethread = std::thread(&Handler<E>::thread_fun, this, std::move(ptr));
  127. }
  128. } else {
  129. run(std::move(event), ptr);
  130. }
  131. }
  132.  
  133. void join() noexcept override {
  134. if(ethread.joinable()) {
  135. ethread.join();
  136. }
  137. }
  138.  
  139. void exit() noexcept override {
  140. if(ethread.joinable()) {
  141. econd.notify_all();
  142. ethread.join();
  143. }
  144. }
  145.  
  146. private:
  147. std::mutex publishing;
  148. ListenerList onceL{};
  149. ListenerList onL{};
  150.  
  151. std::thread ethread;
  152. std::queue<E> events;
  153. std::mutex emutex;
  154. std::condition_variable econd;
  155. };
  156.  
  157. static std::size_t next_type() noexcept {
  158. static std::size_t counter = ;
  159. return counter++;
  160. }
  161.  
  162. template<typename>
  163. static std::size_t event_type() noexcept {
  164. static std::size_t value = next_type();
  165. return value;
  166. }
  167.  
  168. template<typename E>
  169. Handler<E> & handler() noexcept {
  170. std::size_t type = event_type<E>();
  171.  
  172. if(!(type < handlers.size())) {
  173. handlers.resize(type+);
  174. }
  175.  
  176. if(!handlers[type]) {
  177. handlers[type] = std::make_unique<Handler<E>>();
  178. }
  179.  
  180. return static_cast<Handler<E>&>(*handlers[type]);
  181. }
  182.  
  183. protected:
  184. template<typename E>
  185. void publish(E event, bool asyn = false) {
  186. // handler<E>().publish(std::move(event), *static_cast<T*>(this), asyn);
  187. handler<E>().publish(std::move(event), this->shared_from_this(), asyn);
  188. }
  189.  
  190. public:
  191. template<typename E>
  192. using Listener = typename Handler<E>::Listener;
  193.  
  194. /**
  195. * @brief Connection type for a given event type.
  196. *
  197. * Given an event type `E`, `Connection<E>` is the type of the connection
  198. * object returned by the event emitter whenever a listener for the given
  199. * type is registered.
  200. */
  201. template<typename E>
  202. struct Connection: private Handler<E>::Connection {
  203. template<typename> friend class Emitter;
  204.  
  205. Connection() = default;
  206. Connection(const Connection &) = default;
  207. Connection(Connection &&) = default;
  208.  
  209. Connection(typename Handler<E>::Connection conn)
  210. : Handler<E>::Connection{std::move(conn)}
  211. {}
  212.  
  213. Connection & operator=(const Connection &) = default;
  214. Connection & operator=(Connection &&) = default;
  215. };
  216.  
  217. virtual ~Emitter() noexcept {
  218. static_assert(std::is_base_of<Emitter<T>, T>::value, "!");
  219. }
  220.  
  221. /**
  222. * @brief Registers a long-lived listener with the event emitter.
  223. *
  224. * This method can be used to register a listener that is meant to be
  225. * invoked more than once for the given event type.<br/>
  226. * The Connection object returned by the method can be freely discarded. It
  227. * can be used later to disconnect the listener, if needed.
  228. *
  229. * Listener is usually defined as a callable object assignable to a
  230. * `std::function<void(const E &, T &)`, where `E` is the type of the event
  231. * and `T` is the type of the resource.
  232. *
  233. * @param f A valid listener to be registered.
  234. * @return Connection object to be used later to disconnect the listener.
  235. */
  236. template<typename E>
  237. Connection<E> on(Listener<E> f) {
  238. return handler<E>().on(std::move(f));
  239. }
  240.  
  241. /**
  242. * @brief Registers a short-lived listener with the event emitter.
  243. *
  244. * This method can be used to register a listener that is meant to be
  245. * invoked only once for the given event type.<br/>
  246. * The Connection object returned by the method can be freely discarded. It
  247. * can be used later to disconnect the listener, if needed.
  248. *
  249. * Listener is usually defined as a callable object assignable to a
  250. * `std::function<void(const E &, T &)`, where `E` is the type of the event
  251. * and `T` is the type of the resource.
  252. *
  253. * @param f Avalid listener to be registered.
  254. * @return Connection object to be used later to disconnect the listener.
  255. */
  256. template<typename E>
  257. Connection<E> once(Listener<E> f) {
  258. return handler<E>().once(std::move(f));
  259. }
  260.  
  261. /**
  262. * @brief Disconnects a listener from the event emitter.
  263. * @param conn A valid Connection object
  264. */
  265. template<typename E>
  266. void erase(Connection<E> conn) noexcept {
  267. handler<E>().erase(std::move(conn));
  268. }
  269.  
  270. /**
  271. * @brief Disconnects all the listeners for the given event type.
  272. */
  273. template<typename E>
  274. void clear() noexcept {
  275. handler<E>().clear();
  276. }
  277.  
  278. /**
  279. * @brief Disconnects all the listeners.
  280. */
  281. void clear() noexcept {
  282. std::for_each(handlers.begin(), handlers.end(),
  283. [](auto &&hdlr){ if(hdlr) { hdlr->clear(); } });
  284. }
  285.  
  286. /**
  287. * @brief Checks if there are listeners registered for the specific event.
  288. * @return True if there are no listeners registered for the specific event,
  289. * false otherwise.
  290. */
  291. template<typename E>
  292. bool empty() const noexcept {
  293. std::size_t type = event_type<E>();
  294.  
  295. return (!(type < handlers.size()) ||
  296. !handlers[type] ||
  297. static_cast<Handler<E>&>(*handlers[type]).empty());
  298. }
  299.  
  300. /**
  301. * @brief Checks if there are listeners registered with the event emitter.
  302. * @return True if there are no listeners registered with the event emitter,
  303. * false otherwise.
  304. */
  305. bool empty() const noexcept {
  306. return std::all_of(handlers.cbegin(), handlers.cend(),
  307. [](auto &&hdlr){ return !hdlr || hdlr->empty(); });
  308. }
  309.  
  310. void thread_join() const noexcept {
  311. std::for_each(handlers.begin(), handlers.end(),
  312. [](auto &&hdlr){ if(hdlr) { hdlr->join(); } });
  313. }
  314.  
  315. void thread_exit() const noexcept {
  316. std::for_each(handlers.begin(), handlers.end(),
  317. [](auto &&hdlr){ if(hdlr) { hdlr->exit(); } });
  318. }
  319.  
  320. private:
  321. std::vector<std::unique_ptr<BaseHandler>> handlers{};
  322. };

emitter.h

Emitter类应该和项目是兼容的,但是为了更干净和通用一点,去除了ErrorEvent这些东西,所以已经不适合再放到源码里。下面是使用的例子:

  1. #include <iostream>
  2. #include <memory>
  3. #include <thread>
  4.  
  5. using namespace std;
  6. #include "emitter.h"
  7.  
  8. struct StringEvent
  9. {
  10. StringEvent(std::string str):i_str(str)
  11. {
  12. cout << "StringEvent" << std::endl;
  13. }
  14.  
  15. void print()
  16. {
  17. std::cout << "string event:" << i_str << std::endl;
  18. }
  19.  
  20. std::string i_str;
  21.  
  22. ~StringEvent()
  23. {
  24. cout << "~StringEvent" << std::endl;
  25. }
  26. };
  27.  
  28. struct IntEvent
  29. {
  30. IntEvent(int t) : i_t(t)
  31. {
  32. cout << "IntEvent" << std::endl;
  33. }
  34. void print()
  35. {
  36. std::cout << "int event:" << i_t << std::endl;
  37. }
  38. ~IntEvent()
  39. {
  40. cout << "~IntEvent" << std::endl;
  41. }
  42.  
  43. int i_t{};
  44. };
  45.  
  46. class A : public Emitter<A>
  47. {
  48. public:
  49. A()
  50. {
  51. cout << "A" << endl;
  52. }
  53.  
  54. void print()
  55. {
  56. publish(StringEvent("Hello"), false);
  57. publish(make_event<StringEvent>("Hello"), true);
  58. publish(make_unique<StringEvent>("World"), true);
  59.  
  60. this_thread::sleep_for(1000ms);
  61. publish(make_unique<IntEvent>(), true);
  62. publish(make_unique<IntEvent>(), true);
  63.  
  64. }
  65.  
  66. ~A()
  67. {
  68. cout << "~A" << endl;
  69. }
  70. };
  71.  
  72. int main()
  73. {
  74. shared_ptr<A> em = make_shared<A>();
  75.  
  76. em->on<StringEvent>([](StringEvent& ev, shared_ptr<A>& a){
  77. ev.print();
  78. });
  79.  
  80. em->on<event_ptr<StringEvent>>([](event_ptr<StringEvent>& ev, shared_ptr<A>& a){
  81. ev->print();
  82. });
  83.  
  84. em->on<event_ptr<IntEvent>>([](event_ptr<IntEvent>& ev, shared_ptr<A>& a){
  85. ev->print();
  86. });
  87.  
  88. em->print();
  89.  
  90. em->thread_join();
  91.  
  92. return ;
  93. }

test.cc

主要来看看做的一些改动。

先看test.cc里面,现在的事件处理函数Lambda中的两个参数做了改变:

  1. em->on<StringEvent>([](StringEvent& ev, shared_ptr<A>& a){
  2. ev.print();
  3. });

第二个参数由原来的 A& 类型 改成了 share_ptr<A>& 类型。

  1. class A : public Emitter<A>
  2. {
  3. public:
  4. A()
  5. {
  6. cout << "A" << endl;
  7. }
  8.  
  9. void print()
  10. {
  11. publish(StringEvent("Hello"), false);
  12. publish(make_event<StringEvent>("Hello"), true);
  13. publish(make_unique<StringEvent>("World"), true);
  14.  
  15. this_thread::sleep_for(1000ms);
  16. publish(make_unique<IntEvent>(), true);
  17. publish(make_unique<IntEvent>(), true);
  18.  
  19. }
  20.  
  21. ~A()
  22. {
  23. cout << "~A" << endl;
  24. }
  25. };

我们看过之前的代码,现在在publish中多加了一个bool参数,默认值为false,用于指示这个事件是否需要异步处理。

这里注意下,指示异步处理的是在发生事件,调用publish的时候。

用法上面主要就这些改动,然后再来看emitter.h

Handler类

  1. template<typename E>
  2. struct Handler final: BaseHandler {
  3. using Listener = std::function<void(E &, std::shared_ptr<T>&)>;
  4. using Element = std::pair<bool, Listener>;
  5. using ListenerList = std::list<Element>;
  6. using Connection = typename ListenerList::iterator;
  7.  
  8. bool empty() const noexcept override {
  9. auto pred = [](auto &&element){ return element.first; };
  10.  
  11. return std::all_of(onceL.cbegin(), onceL.cend(), pred) &&
  12. std::all_of(onL.cbegin(), onL.cend(), pred);
  13. }
  14.  
  15. void clear() noexcept override {
  16. if(!publishing.try_lock()) {
  17. auto func = [](auto &&element){ element.first = true; };
  18. std::for_each(onceL.begin(), onceL.end(), func);
  19. std::for_each(onL.begin(), onL.end(), func);
  20. } else {
  21. onceL.clear();
  22. onL.clear();
  23. }
  24. publishing.unlock();
  25. }
  26.  
  27. Connection once(Listener f) {
  28. return onceL.emplace(onceL.cend(), false, std::move(f));
  29. }
  30.  
  31. Connection on(Listener f) {
  32. return onL.emplace(onL.cend(), false, std::move(f));
  33. }
  34.  
  35. void erase(Connection conn) noexcept {
  36. conn->first = true;
  37.  
  38. if(publishing.try_lock()) {
  39. auto pred = [](auto &&element){ return element.first; };
  40. onceL.remove_if(pred);
  41. onL.remove_if(pred);
  42. }
  43. publishing.unlock();
  44. }
  45.  
  46. void run(E event, std::shared_ptr<T> ptr) {
  47. ListenerList currentL;
  48. onceL.swap(currentL);
  49.  
  50. auto func = [&event, &ptr](auto &&element) {
  51. return element.first ? void() : element.second(event, ptr);
  52. };
  53.  
  54. publishing.lock();
  55.  
  56. std::for_each(onL.rbegin(), onL.rend(), func);
  57. std::for_each(currentL.rbegin(), currentL.rend(), func);
  58.  
  59. publishing.unlock();
  60.  
  61. onL.remove_if([](auto &&element){ return element.first; });
  62. }
  63.  
  64. void thread_fun(std::shared_ptr<T> ptr)
  65. {
  66. while(true) {
  67. std::unique_lock<std::mutex> lk(emutex);
  68. econd.wait_for(lk, std::chrono::milliseconds(), [this](){return !events.empty();});
  69.  
  70. if(events.size() > ) {
  71. E event = std::move(events.front());
  72. events.pop();
  73. run(std::move(event), std::move(ptr));
  74. } else {
  75. break;
  76. }
  77. }
  78. }
  79.  
  80. void publish(E event, std::shared_ptr<T> ptr, bool asyn) {
  81. if(asyn) {
  82. {
  83. std::lock_guard<std::mutex> lk(emutex);
  84. events.push(std::move(event));
  85. }
  86. econd.notify_all();
  87.  
  88. if(!ethread.joinable()) {
  89. ethread = std::thread(&Handler<E>::thread_fun, this, std::move(ptr));
  90. }
  91. } else {
  92. run(std::move(event), ptr);
  93. }
  94. }
  95.  
  96. void join() noexcept override {
  97. if(ethread.joinable()) {
  98. ethread.join();
  99. }
  100. }
  101.  
  102. void exit() noexcept override {
  103. if(ethread.joinable()) {
  104. econd.notify_all();
  105. ethread.join();
  106. }
  107. }
  108.  
  109. private:
  110. std::mutex publishing;
  111. ListenerList onceL{};
  112. ListenerList onL{};
  113.  
  114. std::thread ethread;
  115. std::queue<E> events;
  116. std::mutex emutex;
  117. std::condition_variable econd;
  118. };

在里面添加了存放事件的队列,还有用于同步的mutex和条件变量。在publish的时候,区分了异步调用,并且创建了线程。这里写几点重要的东西,

1、创建线程时为了可以传入Emitter,将原来的T&改为了share_ptr<T>,可以看emitter.h源码188~192

  1. template<typename E>
  2. void publish(E event, bool asyn = false) {
  3. // handler<E>().publish(std::move(event), *static_cast<T*>(this), asyn);
  4. handler<E>().publish(std::move(event), this->shared_from_this(), asyn);
  5. }

这里之所以可以用 this->shared_from_this() 来获得类的share_ptr 是因为该类继承了std::enable_shared_from_this,可以看emitter.h源码第33行,类原型大概是这样。

  1. template<typename T>
  2. class Emitter : public std::enable_shared_from_this<T> {}

2、在thread_fun中,设置了默认等待时间为60000ms,也就是1分钟。如果在1分钟内没有事件交由线程处理,那么线程会退出,避免浪费资源。有些看官会说了,那如果我事件就是1分钟发生一次呢,那岂不是每次都要重新创建线程?是的,是需要重新创建,所以大家根据要求来改吧,KeKe~

3、对于相同的事件类型,是否会在线程中处理,和事件的注册没有任何关系,而是在事件发送,也就是publish的时候确定的。考虑到一些场景,比如写日志,同样是日志事件,但是有的日志非常长,需要大量io时间,有的日志比较短,不会浪费很多io时间。那就可以在publish的时候根据日志数据大小来决定,是否需要用异步操作。

4、将原先的bool publishing 改为std::mutex publishing,防止线程中对ListenerList的操作会造成的未知情况。

接下来说一下事件和事件的发送。

对于事件类型,就是一个普通的结构体或类,比如test.cc中的StringEvent 和 IntEvent。但是publish时对Event的构建有时候是可能影响一些性能的,先看test.cc中的48~96:

  1. class A : public Emitter<A>
  2. {
  3. public:
  4. A()
  5. {
  6. cout << "A" << endl;
  7. }
  8.  
  9. void print()
  10. {
  11. publish(StringEvent("Hello"), false);
  12. publish(make_event<StringEvent>("Hello"), true);
  13. publish(make_unique<StringEvent>("World"), true);
  14.  
  15. this_thread::sleep_for(1000ms);
  16. publish(make_unique<IntEvent>(), true);
  17. publish(make_unique<IntEvent>(), true);
  18.  
  19. }
  20.  
  21. ~A()
  22. {
  23. cout << "~A" << endl;
  24. }
  25. };
  26.  
  27. int main()
  28. {
  29. shared_ptr<A> em = make_shared<A>();
  30.  
  31. em->on<StringEvent>([](StringEvent& ev, shared_ptr<A>& a){
  32. ev.print();
  33. });
  34.  
  35. em->on<event_ptr<StringEvent>>([](event_ptr<StringEvent>& ev, shared_ptr<A>& a){
  36. ev->print();
  37. });
  38.  
  39. em->on<event_ptr<IntEvent>>([](event_ptr<IntEvent>& ev, shared_ptr<A>& a){
  40. ev->print();
  41. });
  42.  
  43. em->print();
  44.  
  45. em->thread_join();
  46.  
  47. return ;
  48. }

把以上的12~17行,注释掉,可以得到结果:

  1. A
  2. StringEvent
  3. string event:Hello
  4. ~StringEvent
  5. ~StringEvent
  6. ~StringEvent
  7. ~A

可以看到StringEvent构造了一次,但是却析构了3次,非常恐怖。原因是我们在publish中调用std::move来传递参数。实际上std::move是会调用类的移动构造函数的,但是咱们这里只是在构造函数里打印了一下,所以实际上这里应该是创建了3次StringEvent的,比如这里的StringEvent,移动构造函数的原型应该是

  1. StringEvent(StringEvent&& e){std::cout << "StringEvent" << endl;}

如果把这句加到StringEvent类中去,就会多打印两次 "StringEvent" 了,大家可以动手试试。

很明显,这里使用了移动构造函数,多构建了两次StringEvent,对于Event结构中如果比较复杂,很可能会影响效率,所以我又在emitter.h中加了几行,文件19~26

  1. template<typename E>
  2. using event_ptr = std::unique_ptr<E>;
  3.  
  4. template<typename E, typename... Args>
  5. event_ptr<E> make_event(Args&&... args) {
  6. return std::make_unique<E>(std::forward<Args>(args)...);
  7. }

它的用法在上面代码中有体现,这儿其实就是封装了一下make_unique,用make_unique来构建事件,其实这时候事件类型已经不是E,而是std::unique_ptr<E>,在main函数中有体现,大家可以比对一下看看。这样做的好处就是,Event只构建了一次,某种程度上是会提高点效率的。

好了,这个东西介绍到这里,还没来得及多测试一下,就贴出来了。有问题提出来,大家一起讨论。

下一篇不出意外的话,就继续来看源码,KeKe~

我还不知道博客园哪里可以上传文件,等我研究一下,把代码传上来。再贴链接。 emitter

----------------2017/9/25更新--------------------

上次没来得及仔细测试,下午没事就好好测试了一下,发现里面有很多错误的地方,我已经在代码中进行了修改并重新上传了,下载地址应该还是一样的。

上面写的我就不修改了,作为反面教材吧,KeKe~。另外再说一些东西:

1、thread::joinable,之前我用这个来判断线程是否在运行是错误的,joinable只是返回一种线程状态,用来指明该线程是否可以用join来等待线程结束。如果使用了detch,将线程和主线程分离了,就不能再使用join了。

2、wait_for,之前我把等待条件放在wait_for中的第三个参数,我们调用notify_all后, wait_for会调用匿名函数,如果条件不满足,就继续等直到超时(注意这里的超时时间还是和给定的参数一样);如果条件满足就返回。现在假设我们wait_for的超时时间非常过长,但是已经没有事件了,这时候我们调用notify_all来终止线程是错误的,原因上面已经说了。这在新代码中作了改进。

3、添加了wait函数,用于等待所有事件的回调结束,并且线程结束。当然这只针对异步的事件。

给大家造成了困扰, 在这里深感抱歉。

UVW源码漫谈(番外篇)—— Emitter的更多相关文章

  1. UVW源码漫谈(三)

    咱们继续看uvw的源码,这次看的东西比较多,去除底层的一些东西,很多代码都是连贯的,耦合度也比较高了.主要包括下面几个文件的代码: underlying_type.hpp resource.hpp l ...

  2. UVW源码漫谈(四)

    十一假期后就有点懒散,好长时间都没想起来写东西了.另外最近在打LOL的S赛.接触LOL时间不长,虽然平时玩的比较少,水平也相当菜,但是像这种大型的赛事有时间还是不会错过的.主要能够感受到选手们对竞技的 ...

  3. UVW源码漫谈(二)

    前一篇发布出来之后,我看着阅读量还是挺多的,就是评论和给意见的一个都没有,或许各位看官就跟我一样,看帖子从不回复,只管看就行了.毕竟大家都有公务在身,没太多时间,可以理解.不过没关系,我是不是可以直接 ...

  4. 【转】tars源码漫谈第1篇------tc_loki.h (牛逼哄哄的loki库)

    loki库是C++模板大牛Andrei写的, 里面大量运用模板的特性, 而tc_loki.h借用了loki库的部分代码, 形成了一个基本的文件tc_loki.h, 来看看: #ifndef __TC_ ...

  5. iOS冰与火之歌(番外篇) - 基于PEGASUS(Trident三叉戟)的OS X 10.11.6本地提权

    iOS冰与火之歌(番外篇) 基于PEGASUS(Trident三叉戟)的OS X 10.11.6本地提权 蒸米@阿里移动安全 0x00 序 这段时间最火的漏洞当属阿联酋的人权活动人士被apt攻击所使用 ...

  6. 给深度学习入门者的Python快速教程 - 番外篇之Python-OpenCV

    这次博客园的排版彻底残了..高清版请移步: https://zhuanlan.zhihu.com/p/24425116 本篇是前面两篇教程: 给深度学习入门者的Python快速教程 - 基础篇 给深度 ...

  7. 【重走Android之路】【番外篇】有关于null的一些知识点

    [重走Android之路][番外篇]有关于null的一些知识点   1.首先,到底什么是null? null是Java中的一个关键字,用于表示一个空对象引用,但其本身并不是任何类型也不是属于任何对象. ...

  8. [置顶] think in java interview番外篇-谈程序员如何修练英语

    一.程序员对英语能力的重视度和能力要求应该是在各行各业中排在比较靠前的 这样说吧,英语程度的好坏直接影响着一个程序员的编程.开发.创新能力. 道理很简单: 1. 计算机和软件是用英语创造出来的 2. ...

  9. 知识图谱实战开发案例剖析-番外篇(1)- Neo4j是否支持按照边权重加粗和大数量展示

    一.前言 本文是<知识图谱实战开发案例完全剖析>系列文章和网易云视频课程的番外篇,主要记录学员在知识图谱等相关内容的学习 过程中,提出的共性问题进行展开讨论.该部分内容原始内容记录在网易云 ...

随机推荐

  1. [2017-05-31]Abp介绍和经验分享-目录

    很久没动博客了,人比较懒. 最近想写点啥,主要就介绍下ABP框架和我这两年的使用经验. 文档翻译之类的工作就算了,需要的请参考: 官方文档 PS:官方文档末尾有中文文档的链接,这里就不贴了 先列个提纲 ...

  2. Ext:添加进度条

    var myMask = new Ext.LoadMask(Ext.getBody(), {msg:"正在提交..."}); myMask.show(); myMask.hide( ...

  3. HTML5_input_file_打开很慢的问题

    最近项目中有上传附件的功能,只是在chrome浏览器上面测试,发现上传附件,打开选择框比较慢 原文链接:http://www.foreverpx.cn

  4. jmeter性能测试 套路一

     真的跑压力,都是master-slave的方式,部署在压力机上跑性能测试  本机一般都是调试.

  5. MongoDB副本集模式安装

    设备: 三个1G.20G.1核的虚拟机,系统是SentOS7 min 设置目录: Server1: mkdir -p /home/mongoshard/data/shard11 /home/mongo ...

  6. MySQL常见的三种存储引擎(InnoDB、MyISAM、MEMORY)

    简单来说,存储引擎就是指表的类型以及表在计算机上的存储方式. 存储引擎的概念是MySQL的特点,Oracle中没有专门的存储引擎的概念,Oracle有OLTP和OLAP模式的区分.不同的存储引擎决定了 ...

  7. struts.xml如何加载到及配置问题

    今天项目做客户化处理,看到struts.xml,突然间想不起来这个文件从哪里加载的了,真是越学越回去了.这里记录下. web工程启动的时候,系统会加载web.xml文件,在这个时候会加载Spring的 ...

  8. chrome开发工具指南(一)

    注意:如果你是一个网页开发者同时想要获得最新版本的开发工具,那么你应该使用谷歌浏览器(金丝雀)Canary 版. Chrome 开发者工具 打开Chrome 开发者工具 选择浏览器位于浏览器窗口右上方 ...

  9. Spring上传文件,图片,以及常见的问题

    1. 在工程依赖库下添加文件上传jar包 commons-fileupload-1.2.2.jar commons-io-2.4.jar 2.在springMVC配置文件中配置视图解析multipar ...

  10. Project 4:Longest Ordered Subsequence

    Problem description A numeric sequence of ai is ordered if a1 < a2 < - < aN. Let the subseq ...