Error

C++博客 首页 新随笔 联系 聚合 管理
  217 Posts :: 61 Stories :: 32 Comments :: 0 Trackbacks
@网友
duilib的Dump对象里边有一个临界区对象,有几个函数是被保护起来的。注释掉就好了。
re: cocos2dx-quick 01 Enic 2015-04-06 23:29
--class方法有两个参数,第一个参数是类名,第二个参数可以通过两种形式传入 --一种是传入一个函数,一种是传入一个Quick的类,或者Lua对象 --当传入函数时,新创建的类会以传入的函数作为构造函数,当传入的是一个对象时,会以传入的对象为父类派生下来。
后续的技能工具,宠物工具都没有本质变化,不再这样分析了。
整个的思路都是以配置表填充游戏世界,细节上没有其他亮点,没有特别出彩的数据结构设计,大部分都是大一统的配置表格。
后续出一个客户端整个表格设计的概览,然后分析其他的东东
用boost::shared_ptr 或者std::shared_ptr的时候没有这个问题,我猜测是共享数据卡里边保留了原始指针,,,@Chipset
linux各种坑
我们3.x的项目刚刚到中期,,,
re: lua的编码风格很爽啊 Enic 2014-06-27 14:05
@ccsdu2009
啥意思?
re: Muduo源码阅读 Enic 2014-05-05 10:47
楼主用的什么工具看的啊?
re: std::bind2nd简单理解 Enic 2014-03-16 19:02
1.std::bind2nd std::bind1st 用于参数绑定
2.std::binary_function 等用于支持std::bind2nd std::bind1st
3.std::mem_fun1用于从普通函数构造出派生于binary_function临时对象支持bind系列
感觉应该附上公司或者项目方向会合适一点
re: 撸UI库:01 Enic 2013-12-02 20:04
@cpper
有计划,山寨的三个对象中,两个对象支持硬件加速,最开始看上chromium是应为skia的硬件加速和跨平台性,由于个人原因作罢。
抄袭的对象uileeihcy采用的是插件设计,render是可替换的。
编译chromium的时候也遇到了同样的问题,各种定义都无效,最后还是找到原来的帖子,,,唉,,,

在C/C++ --> “预处理器”--> “预处理定义”中增加以下行即可:
_VARIADIC_MAX=10

这一招生效了,,,
re: boost::atomic 实现 spinlock Enic 2013-03-31 23:52
老外是这么说的:

http://cbloomrants.blogspot.be/2011/07/07-14-11-compareexchangestrong-vs.html


07-14-11 - compare_exchange_strong vs compare_exchange_weak

The C++0x standard was revised a while ago to split compare_exchange (aka CAS) into two ops. A quick note on the difference :

bool compare_exchange_weak( T * ptr, T * old, T new );

bool compare_exchange_strong( T * ptr, T * old, T new );

(BTW in the standard "old" is actually a reference, which is a damn shitty thing to do because it makes it very non-transparent that "old" gets mutated by these functions, so I am showing it as a pointer).
both try to do :


atomically {
if ( *ptr == *old ) { *ptr = new; return true; }
else { *old = *ptr; return false; }
}

the difference is that compare_exchange_weak can also return false for spurious failure. (the original C++0x definition of CAS always allowed spurious failure; the new thing is the _strong version which doesn't).
If it returns due to spurious failure, then *old might be left untouched (and in fact, *ptr might be equal to *old but we failed anyway).

If spurious failure can only occur due to contention, then you can still gaurantee progress. In fact in the real world, I believe that LL-SC architectures cannot gaurantee progress, because you can get spurious failure if there is contention anywhere on the cache line, and you need that contention to be specifically on your atomic variable to gaurantee progress. (I guess if you are really worried about this, then you should ensure that atomic variables are padded so they get their own cache line, which is generally good practice for performance reasons anyway).

On "cache line lock" type architectures like x86, there is no such thing as spurious failure. compare_exchange just maps to "cmpxchg" instruction and you always get the swap that you want. (it can still fail of course, if the value was not equal to the old value, but it will reload old). (BTW it's likely that x86 will move away from this in the future, because it's very expensive for very high core counts)

compare_exchange_weak exists for LL-SC (load linked/store conditional) type architectures (Power, ARM, basically everything except x86), because on them compare_exchange_strong must be implemented as a loop, while compare_exchange_weak can be non-looping. For example :

On ARM, compare_exchange_weak is something like :

compare_exchange_weak:

ldrex // load with reservation
teq // test equality
strexeq // store if equal
and strexeq can fail for two reasons - either because they weren't equal, or because the reservation was lost (because someone else touched our cache line).
To implement compare_exchange_strong you need a loop :

compare_exchange_strong:

while ( ! compare_exchange_weak(ptr,old,new) ) { }

(note that you might be tempted to put a (*old = *ptr) inside the loop, but that's probably not a good idea, and not necessary, because compare_exchange_weak will eventually load *ptr into *old itself when it doesn't fail spuriously).
The funny bit is that when you use compare_exchange you often loop anyway. For example say I want to use compare_exchange_strong to increment a value, I have to do :


cur = *ptr;
while( ! compare_exchange_strong(ptr,&cur,cur+1) ) { }

(note it's a little subtle that this works - when compare_exchange_strong fails, it's because somebody else touched *ptr, so we then reload cur (this is why "old" is passed by address), so you then recompute cur+1 from the new value; so with the compare_exchange_strong, cur has a different value each time around this loop.)
But on an LL-SC architecture like ARM this becomes a loop on a loop, which is dumb when you could get the same result with a single loop :


cur = *ptr;
while( ! compare_exchange_weak(ptr,&cur,cur+1) ) { }

Note that with this loop now cur does *not* always take a new value each time around the loop (it does when it fails due to contention, but not when it fails just due to reservation-lost), but the end result is the same.
So that's why compare_exchange_weak exists, but you might ask why compare_exchange_strong exists. If we always use loops like this, then there's no need for it. But we don't always use loops like this, or we might want to loop at the much higher level. For example you might have something like :

bool SpinLock_TryLock(int * lock)
{
int zero = 0;
return compare_exchange_strong(lock,&zero,1);
}
which returns false if it couldn't get the lock (and then might do an OS wait) - you don't want to return false just because of a spurious failure. (that's not a great example, maybe I'll think of a better one later).
(BTW I think the C++0x stuff is a little bit broken, like most of C standardization, because they are trying to straddle this middle ground of exposing the efficient hardware-specific ways of doing things, but they don't actually expose enough to map directly to the hardware, and they also aren't high level enough to separate you from knowing about the hardware. For example none of their memory model actually maps directly to what x86 provides, therefore there are some very efficient x86-specific ways to do threading ops that cannot be expressed portable in C++0x. Similarly on LL-SC architectures, it would be preferrable to just have access to LL-SC directly.

I'd rather see things in the standard like "if LL-SC exist on this architecture, then they can be invoked via __ll() and __sc()" ; more generally I wish C had more conditionals built into the language, that would be so much better for real portability, as opposed to the current mess where they pretend that the language is portable but it actually isn't so you have to create your own mess of meta-language through #defines).
class CBase
{
public:
int i[255];

virtual ~CBase()
{
}
};

多谢大侠指点,加上以后能正常delete@剑孤寒
可能我的表述有问题。
当时是针对另一个场景所谓的只读:我需要在遍历过程中删除部分节点。

感谢指出来,这个细节还需要继续深挖@P
我搜索下代码看看,确实有这个东西,看注释应该是可以选择启用,关闭,或者使用gtest自带的版本@无
re: (转)C宏技巧汇总 Enic 2012-12-11 10:47
你问的比较抽象哟@xyl
一开始不要做框架,先考虑做成基础库。
基础库成熟了,框架就呼之欲出了。应为你现在还不够了解这里边的道道,所以直接去做框架是很可能南辕北辙的。
可以先参考QT WTL MFC的设计思想,然后以实际项目为导向。
如果是做界面有一本老书推荐给你:《道法自然》

还有如果你定位是windows平台,可以考虑用ATL包装窗口,ATL的窗口循环hack已经做好了,而且做稳定了。
"因此2进制文件的可移植性好。"

书上说的是字符可移植性好,你可能没有考虑到异构系统
首先膜拜一下大神,,,

svn刚刚更新了代码,发现一点点小问题
file:examples\igantt\gantt_main.cpp
line:PathProvider(base::DIR_EXE, &res_dll);
编译器说不认识这货,,,


后来把这两货移动到 path_service.h, chrome编译通过
namespace base
{

bool PathProvider(int key, FilePath* result);
bool PathProviderWin(int key, FilePath* result);

}


再后来igantt在链接的时候连接器说不认识这货
_modp_b64_encode
估计要重新编译base lib,
正在编译ing
无效
搜索代码,好像这个函数确实没有。终于被我找到一个bug了,,,



××××××××××××××××××××××××××××××××××××××××
博客追了很久了,第一次冒泡。
说来惭愧,小弟道行不够,直接看chrome差点傻眼了,只能跟着大神的脚步了,,,希望跟得上,,,
再次谢过博主大神的无私奉献,,,
楼上非常正确,,,
@华夏之火
楼主已经很客气了,,,
并不非要全部用a b c 1 2 3代码揉成一团才是牛逼算法,,,
re: C++杂谈 Enic 2011-07-11 10:14
90%赞同,感同身受,,,
愚以为,组装工厂自动化流水线更合适,,,
re: IOCP完成端口源代码 Enic 2011-07-04 15:15
楼主,你确定你用的是Window IOCP技术?
虽然不知道楼主在说什么,但是感觉楼主很牛逼,,,

膜拜大神啊,,,
膜拜大神,求带,,,

我折腾好久了,,,七窍都通了六窍了,,,
@ray ban glasses

这个是真洋鬼子?
@千暮(zblc)
我囧,,,一楼也是哥,,,

大神太牛逼了,偶以前就见过这个lib,才发现原来是这里的神仙搞出来的,,,
这世上原本没有神仙,后来有人做了人想做但是做不到的事情,神就诞生了,,,


膜拜大神啊~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(后面的注意保持队形~~)
囧,,,哥昨天晚上不小心膜拜了一下,,,

你们这群神棍就全部跳出来了,,,

膜拜大神啊,,,
膜拜大神啊,,,