![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++
文章平均质量分 62
kofshower
这个作者很懒,什么都没留下…
展开
-
gcc的默认allocator使用malloc和free
Using GCC, you can force the STL to use malloc and to free memory as soon as possible by globally disabling memory caching. Beware! Doing so will probably slow down your program, sometimes原创 2010-03-02 11:46:00 · 1110 阅读 · 1 评论 -
rdtsct tricky hack
static inline uint64 rdtsc() { unsigned int lo, hi;#ifdef __linux__ /* We cannot use "=A", since this would use %rax on x86_64 */ __asm__ __volatile__ ( "rdtsc" : "=a"原创 2012-04-07 23:59:39 · 529 阅读 · 0 评论 -
线程同步对象的实现
struct futex { volatile int lock; volatile int count;};#define LARGE_ENOUGH_NEGATIVE -0x7fffffff#ifdef __cplusplusextern "C" {#endifstatic inline voidfutex_init(struct futex* pf, int cou原创 2012-04-08 11:42:31 · 778 阅读 · 0 评论 -
__asm__("pause")用法
static inline int // return old valueatomic_add(volatile int *count, int add){#ifdef __linux__ __asm__ __volatile__( "lock xadd %0, (%1);" : "=a"(add) : "r"(count), "a"(add) : "memory"原创 2012-04-06 15:48:16 · 2969 阅读 · 0 评论 -
double-locked singleton (spinlock version)
static inline int // return old valueatomic_add(volatile int *count, int add){#ifdef __linux__ __asm__ __volatile__( "lock xadd %0, (%1);" : "=a"(add) : "r"(count), "a"(add) : "memory"原创 2012-04-06 20:30:17 · 638 阅读 · 0 评论 -
c++跨平台的那些事
1、同样语义的接口太多,很多人搞不清区别 swap和operator = 的性能差别2、容器的一些边界情况没有说明清楚 有人认为string是内存连续的容器。 gcc自带的hash_map在什么情况下性能急剧抖动?原创 2011-08-25 08:30:27 · 570 阅读 · 0 评论 -
多重继承和void*的糗事
<br />Author:Kevin LynxDate:4.30.2011<br />C++为了兼容C,导致了不少语言阴暗面。Bjarne Stroustrup在<D&E>一书里也常为此表现出无奈。另一方面,强制转换也是C++的一大诟病。但是,因为我们的应用环境总是那么“不 纯”,所以也就常常导致各种问题。问题<br />考虑下面非常普通的多重继承代码:class Left {public: virtual void ldisplay () { printf ("Left::转载 2011-05-06 09:45:00 · 376 阅读 · 0 评论 -
Boost asio的一个有趣的api
今天用asio做单元测试的时候遇到一个有趣的事情。大约是在debug版本下面的,随机地抛出一个异常。错误如下:通过查看errorcode可以知道是10057,socket未连接的错误。就是说我在发送数据的时候,socket连接没有建立。首先,我检查了代码大约是这样的:LOG4CXX_INFO(Logger::getLogger("runLogger"), "Run TestCa原创 2010-05-27 14:18:00 · 817 阅读 · 0 评论 -
密码学的一些名词字典
Technical Cryptographic Terms Explained原创 2010-07-05 18:55:00 · 365 阅读 · 0 评论 -
c++ Double-locked idiom
在老版本的java中Double-Locked是不安全的例如:public static Singleton getInstance(){ if (instance == null) { synchronized(Singleton.class) { //1 if (instance == null) //2 ins原创 2010-04-15 10:37:00 · 461 阅读 · 0 评论 -
变长引用计数型小对象池实现
class CTranBufPool : public CBufPoolV{ struct Handle { DLINK link; char* pBuffer; Handle* pRealHdl; int nRef; int nConsBuf; }; typedef TLinkedList FreeList; typedef std::map原创 2012-04-10 15:36:51 · 661 阅读 · 0 评论