`
aigo
  • 浏览: 2722898 次
  • 性别: Icon_minigender_1
  • 来自: 宜昌
社区版块
存档分类
最新评论
文章列表
  2的4次方是16,那么已知幂16,底数2,如何求出指数4?   以C为例: double v = log(16) / log(2); printf("%f\n", v);   输出结果为4.0。   java中的log函数是:Math.log。     
  为什么很多开源软件中的源码中,使用位运算代替取模操作,比如: a%b取模的形式都被替换成了a&(b-1) ,前提条件是:b为2的幂(乘方)。   原因: 位运算实现取模只需5个CPU周期,而取模运算符实现至少需要26个CPU周期(注意,是最少!!!)    原文:http://crazyjvm.iteye.com/blog/1725508   言归正传,大家都知道位运算的效率最高,这也是&取代%的原因,来看个程序: C代码   int main(int argc, char* argv[])  
关键字:阻塞队列、非阻塞队列、性能对比、Non-BlockingQueue、BlockingQueue、benchmark、Performance   原文作者:@玄冬Wong 转载请注明出处:http://aigo.iteye.com/blog/2292169 对阻塞和非阻塞队列进行测试: 1,用boost::lockfree::spsc_queue非阻塞队列;(注:spsc_queue是单个生产者单个消费者线程安全的队列,多个生产者多个消费者线程安全的boost::lockfree::queue理论上没有spsc_queue性能好,当然实际上也是这样。。) 2,使用boost ...
java 1.5提供了一种无锁队列(wait-free/lock-free)ConcurrentLinkedQueue,可支持多个生产者多个消费者线程的环境: http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html   下面这个是网上别人自己实现的一种无锁算法队列,原理和jdk官方的ConcurrentLinkedQueue相似:通过volatile关键字来保证数据唯一性(注:java的volatile和c++的volatile关键字是两码事!),但是里面又 ...
关键字:thead、多线程、锁   lock_guard boost::mutex mutex; boost::lock_guard<boost::mutex> lock(mutex);   unique_lock boost::mutex mutex; boost::unique_lock<boost::mutex> lock(mutex);   如果只是为了保证数据同步,那么lock_guard完全够用; 如果除了同步,还需要使用condition进行阻塞时,那么就需要用unique_lock。 boost还要一个boost:: ...
如果定义了 std::atomic_flag 类型变量,则初始化必须在定义的时候初始化,不能在构造函数中初始化。   如果在构造函数中初始化,则会出现出现下面两种错误 class A { private: std::atomic_flag flag; public: A() { flag = ATOMIC_FLAG_INIT; } }  错误: error C2280: 'std::atomic_flag &std::atomic_flag::operator =(const std::atomic_flag &)': a ...
boost方案 boost提供了三种无锁方案 boost::lockfree::queue: 支持多个生产者和多个消费者线程的无锁队列。 boost::lockfree::stack: 支持多个生产者和多个消费者线程的无锁栈。 boost::lockfree::spsc_queue: 仅支持单个生产者和单个消费者线程的无锁队列。相比boost::lockfree::queue,其效率更高。   注:这些API内部是通过轻量级原子锁实现的lock-free,不是真正意义的无锁。我看到的资料中,貌似只有linux kernel中fifo实现了真正意义上的无锁,但是仅用于与单个消 ...
原文: std::memory_order http://en.cppreference.com/w/cpp/atomic/memory_order   #include <thread> #include <atomic> #include <cassert> #include <string> std::atomic<std::string*> ptr; int data; void producer() { std::string* p = new std::string(&quo ...
  官方文档: UKismetSystemLibrary::QuitGame https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Kismet/UKismetSystemLibrary/QuitGame/index.html   示例: #include "KismetSystemLibrary.h" void ASomeActor::SomeActorFunction() { UKismetSystemLibrary::QuitGame(this, nullptr, EQuitP ...
一个IOCP TCP server的例子: http://www.codeproject.com/Articles/10330/A-simple-IOCP-Server-Client-Class     一个IOCP UDP server的例子: Winsock Registered I/O - Traditional Multi threaded IOCP UDP Example Server http://www.serverframework.com/asynchronousevents/2012/08/winsock-registered-io---traditional ...
  官方:https://support.microsoft.com/en-us/kb/192800 原文:http://www.xuebuyuan.com/833696.html   TIP 1: Use Winsock2 IOCP-capable functions, such as WSASend and WSARecv, over Win32 file I/O functions, such as WriteFile and ReadFile.   提示1:尽量使用WSASend和WSARecv进行数据收发   Socket handles from Microsoft ...
  官方文档: C++ 11 and Modern Language Syntax https://docs-origin.unrealengine.com/latest/INT/Programming/Development/CodingStandard/index.html#c++11andmodernlanguagesyntax    
  编译脚本 在boost_1_60_0.zip解压后的根目录下,新建一个build_boost_1_60_vs2015.bat文件,打来命令行并定位到当前目录下执行该bat文件(不要双击运行!),等待运行完毕即可。 bat文件内容如下:参考自:https://studiofreya.com/2015/12/19/how-to-build-boost-1-60-with-visual-studio-2015/ call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" x86 cd boost_1_60_0 call bo ...
std::shared_mutex http://en.cppreference.com/w/cpp/thread/shared_mutex   GCC5.1才会支持C++17 std::shared_mutex,替代方案是boost::shared_mutex。   boost::shared_mutex官方文档:http://www.boost.org/doc/libs/1_60_0/doc/html/thread/synchronization.html#thread.synchronization.mutex_types.shared_mutex   需要的lib: ...
  原文:http://stackoverflow.com/questions/118945/best-c-c-network-library   Aggregated List of Libraries Boost.Asio is really good. Asio is also available as a stand-alone library. ACE is also good, a bit more mature and has a couple of books to support it. C++ Network Library
Global site tag (gtag.js) - Google Analytics