|
Boost : |
From: Philippe A. Bouchard (philippeb_at_[hidden])
Date: 2002-07-15 21:31:43
Greeting,
After a usefull discussion under comp.lang.c++ newsgroup I've made some
modifications to pointers I've already suggested. I am proposing two
different pointers that emphasize efficienty:
mutable_ptr<>:
- literally breaks some compiler assertions that prevents
std::auto_ptr<> from being easily copied;
- is really beneficial for STL container self destructions - believe me;
- copies are a lot easier to manage: work with secondary pure pointers
assignments;
- member declarations identical to std::auto_ptr<>;
- as fast as std::auto_ptr<>.
shared_ptr<>:
- functionality is similar to boost::shared_ptr<> except:
- reference counters are merged with instanciated objects:
- operator new () is called once in the end (like
boost::shared_ptr<>);
- the pointer is same size as sizeof(void *);
- reference counters are not copied when assignments are called;
- little drawback: assignments work only with other
fdi::shared_ptr<>
- the only change from std::auto_ptr<> interface was that release() was
renamed to share();
- faster than boost::shared_ptr<>.
A personnaly prefer using mptr<> and sptr<> because the code is easier to
read in one line. I won't recommend macros but simply to rename classes.
One other thing: the fdi:: namespace is volatile. I hope someone will share
the same vision of efficienty benefits I have.
Thank you,
Philippe A. Bouchard
begin 666 mutable_ptr.h
M+RH*(" @5&AI<R!F:6QE(&ES('!A<G0@;V8@=&AE($9$22!L:6)R87)I97,*
M(" @0V]P>7)I9VAT("AC*2 R,# R(%!H:6QI<'!E($$N($)O=6-H87)D(#QP
M:&EL:7!P94!F;W)N=7_at_N8V]M/@H*(" @5&AI<R!L:6)R87)Y(&ES(&9R964@
M<V]F='=A<F4[('EO=2!C86X@<F5D:7-T<FEB=71E(&ET(&%N9"]O<@H@("!M
M;V1I9GD@:70@=6YD97(@=&AE('1E<FUS(&]F('1H92!'3E4_at_3&EB<F%R>2!'
M96YE<F%L(%!U8FQI8PH@("!,:6-E;G-E('9E<G-I;VX@,B!A<R!P=6)L:7-H
M960_at_8GD@=&AE($9R964_at_4V]F='=A<F4_at_1F]U;F1A=&EO;BX*"B @(%1H:7,@
M;&EB<F%R>2!I<R!D:7-T<FEB=71E9"!I;B!T:&4@:&]P92!T:&%T(&ET('=I
M;&P_at_8F4@=7-E9G5L+ H@("!B=70_at_5TE42$]55"!!3ED_at_5T%24D%.5%D[('=I
M=&AO=70_at_979E;B!T:&4@:6UP;&EE9"!W87)R86YT>2!O9_at_H@("!-15)#2$%.
M5$%"24Q)5%D@;W(@1DE43D534R!&3U(@02!005)424-53$%2(%!54E!/4T4N
M("!3964@=&AE($=.50H@("!,:6)R87)Y($=E;F5R86P_at_4'5B;&EC($QI8V5N
M<V4_at_9F]R(&UO<F4_at_9&5T86EL<RX*"B @(%EO=2!S:&]U;&0@:&%V92!R96-E
M:79E9"!A(&-O<'D@;V8@=&AE($=.52!,:6)R87)Y($=E;F5R86P_at_4'5B;&EC
M($QI8V5N<V4*(" @86QO;F<@=VET:"!T:&ES(&QI8G)A<GD[('-E92!T:&4@
M9FEL92!#3U!924Y'+DQ)0BX@($EF(&YO="P@=W)I=&4@=&\*(" @=&AE($9R
M964_at_4V]F='=A<F4_at_1F]U;F1A=&EO;BP_at_26YC+BP_at_-3D@5&5M<&QE(%!L86-E
M("T_at_4W5I=&4@,S,P+ H@("!";W-T;VXL($U!(# R,3$Q+3$S,#<L(%5302X*
M*B\*"@HC:69N9&5F($U55$%"3$5?4%127T@*(V1E9FEN92!-551!0DQ%7U!4
M4E]("@H*;F%M97-P86-E(&9D:0I["@IT96UP;&%T92 \8VQA<W,@7U1P/@H)
M<W1R=6-T(&UU=&%B;&5?<'1R"@E["@D)='EP961E9B!?5' @96QE;65N=%]T
M>7!E.PH*"0EM=71A8FQE7W!T<BAE;&5M96YT7W1Y<&4@*B!A7W @/2 P*2 Z
M(&U?<'1R*&%?<"D*"0E["@D)?0H*"0EM=71A8FQE7W!T<BAM=71A8FQE7W!T
M<B!C;VYS=" F(&%?<"D_at_.B!M7W!T<BAA7W N<F5L96%S92_at_I*0H)"7L*"0E]
M"@H)"71E;7!L871E(#QC;&%S<R!?5' Q/@H)"0EM=71A8FQE7W!T<BAM=71A
M8FQE7W!T<CQ?5' Q/B!C;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E(&5L96UE;G1?='EP92 J(&U?<'1R.PH)?3L*"GT*"@HC96YD:68*
`
end
begin 666 shared_ptr.h
M+RH*(" @5&AI<R!F:6QE(&ES('!A<G0@;V8@=&AE($9$22!L:6)R87)I97,*
M(" @0V]P>7)I9VAT("AC*2 R,# R(%!H:6QI<'!E($$N($)O=6-H87)D(#QP
M:&EL:7!P94!F;W)N=7_at_N8V]M/@H*(" @5&AI<R!L:6)R87)Y(&ES(&9R964@
M<V]F='=A<F4[('EO=2!C86X@<F5D:7-T<FEB=71E(&ET(&%N9"]O<@H@("!M
M;V1I9GD@:70@=6YD97(@=&AE('1E<FUS(&]F('1H92!'3E4_at_3&EB<F%R>2!'
M96YE<F%L(%!U8FQI8PH@("!,:6-E;G-E('9E<G-I;VX@,B!A<R!P=6)L:7-H
M960_at_8GD@=&AE($9R964_at_4V]F='=A<F4_at_1F]U;F1A=&EO;BX*"B @(%1H:7,@
M;&EB<F%R>2!I<R!D:7-T<FEB=71E9"!I;B!T:&4@:&]P92!T:&%T(&ET('=I
M;&P_at_8F4@=7-E9G5L+ H@("!B=70_at_5TE42$]55"!!3ED_at_5T%24D%.5%D[('=I
M=&AO=70_at_979E;B!T:&4@:6UP;&EE9"!W87)R86YT>2!O9_at_H@("!-15)#2$%.
M5$%"24Q)5%D@;W(@1DE43D534R!&3U(@02!005)424-53$%2(%!54E!/4T4N
M("!3964@=&AE($=.50H@("!,:6)R87)Y($=E;F5R86P_at_4'5B;&EC($QI8V5N
M<V4_at_9F]R(&UO<F4_at_9&5T86EL<RX*"B @(%EO=2!S:&]U;&0@:&%V92!R96-E
M:79E9"!A(&-O<'D@;V8@=&AE($=.52!,:6)R87)Y($=E;F5R86P_at_4'5B;&EC
M($QI8V5N<V4*(" @86QO;F<@=VET:"!T:&ES(&QI8G)A<GD[('-E92!T:&4@
M9FEL92!#3U!924Y'+DQ)0BX@($EF(&YO="P@=W)I=&4@=&\*(" @=&AE($9R
M964_at_4V]F='=A<F4_at_1F]U;F1A=&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1L.PT*"7L-"@D)
M<VAA<F5D7W!T<CQI;G0^('-P,RAN97<@<VAA<F5D7W!T<CQI;G0^.CIE;&5M
M96YT7W1Y<&4H,3 I*3L-"@D)<VAA<F5D7W!T<CQI;G0^('-P-"AS<#,I.PT*
M#0H)"6-O=70@/#P@(BH@<W S(#T@(B \/" J('-P,R \/"!E;F1L.PT*"0EC
M;W5T(#P\("(J('-P-" ]("(@/#P@*B!S<#0@/#P_at_96YD;#L-"@E]#0H-"@EC
M;W5T(#P\(&5N9&P@/#P@(C,Z(B \/"!E;F1L.PT*"7L-"@D);&ES=#P@;75T
M86)L95]P='(\03X@/B!L,3L-"@D);#$N<'5S:%]B86-K*&YE=R!!*#$P*2D[
M#0H)"6PQ+G!U<VA?8F%C:RAN97<@02_at_Q,2DI.PT*"0EL,2YP=7-H7V)A8VLH
M;F5W($$H,3(I*3L-"@T*"0EL:7-T/"!M=71A8FQE7W!T<CQ!/B ^(&PR*&PQ
M*3L-"@D)8V]U=" \/" B;#$N8F%C:R_at_I(#T@(B \/"!L,2YB86-K*"DN9V5T
M*"D@/#P_at_96YD;#L-"@D)8V]U=" \/" B;#(N8F%C:R_at_I+3YI(#T@(B \/"!L
K,BYB86-K*"DM/FD@/#P_at_96YD;#L-"@E]#0H-"@ER971U<FX@,#L-"GT-"@``
`
end
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk