Module: D:\SOURCE\TMP\rcptr.cpp Group: 'DGROUP' CONST,CONST2,_DATA,_BSS Segment: _TEXT PARA USE32 00000138 bytes Comdat: near ::RCBPtr::RCBPtr() SEGMENT ANY '_TEXT' 00000010 bytes template class RCPtr { T *t; unsigned *r; public: RCPtr() : t(0), r(0) {} RCPtr(const RCPtr &p) : t(p.t), r(p.r) { if(t) ++*r; } ~RCPtr() { if(r && --*r==0) { delete t; delete r; } } RCPtr& operator=(const RCPtr &p) { if(this==&p) return *this; if(r && --*r==0) { delete t; delete r; } t=p.t;r=p.r; if(r) ++*r; return *this; } void bind(T *p) { if(r && --*r==0) { delete t; delete r; } t=p; r=t?new unsigned(1):0; } T* operator->() const { return t; } T& operator*() const { return *t; } }; template class RCBPtr { T *t; unsigned *r; public: RCBPtr() : t(0), r(0) 0000 c7 00 00 00 00 00 mov dword ptr [eax],00000000H 0006 c7 40 04 00 00 00 00 mov dword ptr +4H[eax],00000000H {} 000d c3 ret 000e 8b c0 mov eax,eax No disassembly errors ------------------------------------------------------------ 0000 53 main_ push ebx Comdat: near ::RCBPtr::RCBPtr( ::RCBPtr const near & ) SEGMENT ANY '_TEXT' 00000018 bytes RCBPtr(const RCBPtr &p) 0000 53 push ebx : t(p.t), r(p.r) 0001 8b 1a mov ebx,[edx] 0003 89 18 mov [eax],ebx 0005 8b 52 04 mov edx,+4H[edx] 0008 89 50 04 mov +4H[eax],edx { if(t) ++*r; } 000b 83 38 00 cmp dword ptr [eax],00000000H 000e 74 05 je L12 0010 8b 50 04 mov edx,+4H[eax] 0013 ff 02 inc dword ptr [edx] 0015 5b L12 pop ebx 0016 c3 ret 0017 90 nop No disassembly errors ------------------------------------------------------------ 0001 51 push ecx Comdat: near ::RCBPtr::~RCBPtr() SEGMENT ANY '_TEXT' 00000027 bytes ~RCBPtr() { 0000 53 push ebx 0001 89 c3 mov ebx,eax if(r && --*r==0) { delete t; delete r; } 0003 8b 50 04 mov edx,+4H[eax] 0006 85 d2 test edx,edx 0008 74 19 je L13 000a ff 0a dec dword ptr [edx] 000c 8b 40 04 mov eax,+4H[eax] 000f 83 38 00 cmp dword ptr [eax],00000000H 0012 75 0f jne L13 0014 8b 03 mov eax,[ebx] 0016 e8 00 00 00 00 call void near operator delete( void near * ) 001b 8b 43 04 mov eax,+4H[ebx] 001e e8 00 00 00 00 call void near operator delete( void near * ) } RCBPtr& operator=(const RCBPtr &p) { if(this==&p) return *this; if(r && --*r==0) { delete t; delete r; } t=p.t;r=p.r; if(r) ++*r; return *this; } void bind(T *p) { if(r && --*r==0) { delete t; delete r; } t=p; r=t?new unsigned(1):0; } T& operator*() const { return *t; } }; 0023 89 d8 L13 mov eax,ebx 0025 5b pop ebx 0026 c3 ret No disassembly errors ------------------------------------------------------------ 0002 52 push edx 0003 83 ec 10 sub esp,00000010H void main(void) { RCBPtr p1; 0006 31 d2 xor edx,edx p1.bind(new int(7)); 0008 b8 04 00 00 00 mov eax,00000004H 000d 89 14 24 mov [esp],edx 0010 89 54 24 04 mov +4H[esp],edx 0014 e8 00 00 00 00 call void near * near operator new( int unsigned ) 0019 85 c0 test eax,eax 001b 74 06 je L1 001d c7 00 07 00 00 00 mov dword ptr [eax],00000007H 0023 8b 4c 24 04 L1 mov ecx,+4H[esp] 0027 89 c2 mov edx,eax 0029 85 c9 test ecx,ecx 002b 74 1c je L2 002d ff 09 dec dword ptr [ecx] 002f 8b 44 24 04 mov eax,+4H[esp] 0033 83 38 00 cmp dword ptr [eax],00000000H 0036 75 11 jne L2 0038 8b 04 24 mov eax,[esp] 003b e8 00 00 00 00 call void near operator delete( void near * ) 0040 8b 44 24 04 mov eax,+4H[esp] 0044 e8 00 00 00 00 call void near operator delete( void near * ) 0049 89 14 24 L2 mov [esp],edx 004c 85 d2 test edx,edx 004e 74 16 je L4 0050 b8 04 00 00 00 mov eax,00000004H 0055 e8 00 00 00 00 call void near * near operator new( int unsigned ) 005a 85 c0 test eax,eax 005c 74 06 je L3 005e c7 00 01 00 00 00 mov dword ptr [eax],00000001H 0064 89 c2 L3 mov edx,eax RCBPtr p2=p1; 0066 8b 04 24 L4 mov eax,[esp] 0069 89 54 24 04 mov +4H[esp],edx 006d 89 54 24 0c mov +0cH[esp],edx 0071 89 44 24 08 mov +8H[esp],eax 0075 85 c0 test eax,eax 0077 74 02 je L5 0079 ff 02 inc dword ptr [edx] *p2=24; ++*p1; 007b 8b 44 24 08 L5 mov eax,+8H[esp] 007f c7 00 18 00 00 00 mov dword ptr [eax],00000018H p2.bind(new int(8)); 0085 8b 04 24 mov eax,[esp] 0088 ff 00 inc dword ptr [eax] 008a b8 04 00 00 00 mov eax,00000004H 008f e8 00 00 00 00 call void near * near operator new( int unsigned ) 0094 85 c0 test eax,eax 0096 74 06 je L6 0098 c7 00 08 00 00 00 mov dword ptr [eax],00000008H 009e 8b 5c 24 0c L6 mov ebx,+0cH[esp] 00a2 89 c2 mov edx,eax 00a4 85 db test ebx,ebx 00a6 74 1d je L7 00a8 ff 0b dec dword ptr [ebx] 00aa 8b 44 24 0c mov eax,+0cH[esp] 00ae 83 38 00 cmp dword ptr [eax],00000000H 00b1 75 12 jne L7 00b3 8b 44 24 08 mov eax,+8H[esp] 00b7 e8 00 00 00 00 call void near operator delete( void near * ) 00bc 8b 44 24 0c mov eax,+0cH[esp] 00c0 e8 00 00 00 00 call void near operator delete( void near * ) 00c5 89 54 24 08 L7 mov +8H[esp],edx 00c9 85 d2 test edx,edx 00cb 74 16 je L8 00cd b8 04 00 00 00 mov eax,00000004H 00d2 e8 00 00 00 00 call void near * near operator new( int unsigned ) 00d7 85 c0 test eax,eax 00d9 74 0a je L9 00db c7 00 01 00 00 00 mov dword ptr [eax],00000001H 00e1 eb 02 jmp L9 00e3 31 c0 L8 xor eax,eax 00e5 89 44 24 0c L9 mov +0cH[esp],eax } 00e9 85 c0 test eax,eax 00eb 74 1d je L10 00ed ff 08 dec dword ptr [eax] 00ef 8b 44 24 0c mov eax,+0cH[esp] 00f3 83 38 00 cmp dword ptr [eax],00000000H 00f6 75 12 jne L10 00f8 8b 44 24 08 mov eax,+8H[esp] 00fc e8 00 00 00 00 call void near operator delete( void near * ) 0101 8b 44 24 0c mov eax,+0cH[esp] 0105 e8 00 00 00 00 call void near operator delete( void near * ) 010a 8b 44 24 04 L10 mov eax,+4H[esp] 010e 85 c0 test eax,eax 0110 74 1c je L11 0112 ff 08 dec dword ptr [eax] 0114 8b 44 24 04 mov eax,+4H[esp] 0118 83 38 00 cmp dword ptr [eax],00000000H 011b 75 11 jne L11 011d 8b 04 24 mov eax,[esp] 0120 e8 00 00 00 00 call void near operator delete( void near * ) 0125 8b 44 24 04 mov eax,+4H[esp] 0129 e8 00 00 00 00 call void near operator delete( void near * ) 012e 83 c4 10 L11 add esp,00000010H 0131 5a pop edx 0132 59 pop ecx 0133 5b pop ebx 0134 c3 ret 0135 8d 40 00 lea eax,+0H[eax] No disassembly errors ------------------------------------------------------------ Comdat: char unsigned const near __typesig[] SEGMENT ANY 'DGROUP:CONST2' 00000011 bytes 0000 00 - . 0001 00 00 00 00 DD near ::RCBPtr::RCBPtr() 0005 00 00 00 00 DD near ::RCBPtr::RCBPtr( ::RCBPtr const near & ) 0009 00 00 00 00 DD near ::RCBPtr::~RCBPtr() 000d 08 00 00 00 - .... No disassembly errors ------------------------------------------------------------