1

Topic: shared_ptr Against all

Help with examples with what case ubiquitous usage shared_ptr will be to the detriment? We admit us not strongly performance concerns interest.

2

Re: shared_ptr Against all

Hello, _NN _, you wrote: _NN> Help with examples with what case ubiquitous usage shared_ptr will be to the detriment? _NN> we admit us not strongly performance concerns interest. On mind come a link cross connect. But I doubt that there it, this usage, generally is possible.

3

Re: shared_ptr Against all

Hello, _NN _, you wrote: _NN> Help with examples with what case ubiquitous usage shared_ptr will be to the detriment? _NN> we admit us not strongly performance concerns interest. In case of rash usage shared_ptr with the general to the data access to which of different flows is conducted. Can be a penalty on synchronization. But us performance concerns do not interest

4

Re: shared_ptr Against all

Hello, Vain, you wrote: V> Hello, _NN _, you wrote: _NN>> Help with examples with what case ubiquitous usage shared_ptr will be to the detriment? V> on mind come a link cross connect. But I doubt that there it, this usage, generally is possible. For example boost:: asio encourages usage shared_prt + shared_from_this for control over lifetime , and in this case to dig in guts  a cross connect-reference or a copy shared_ptr on itself it is possible easily and easy. I as a result of ringleaders separate tests that output agents are deleted when am necessary.

5

Re: shared_ptr Against all

Hello, _NN _, you wrote: _NN> Help with examples with what case ubiquitous usage shared_ptr will be to the detriment? Circular references are a main trouble. Cut cycles with the help weak_ptr or crude not owning pointers, but it is the most difficult to find cycles, rather than them to tear. Sometimes after implementation weak_ptr there is a problem "object too early died, anybody does not hold it" often there are bookmarks on the order of destruction of objects, here shared_ptr will hinder is a second trouble more likely. Sometimes it would be desirable to make reset and to be assured that here  and fulfills. Sometimes saw through methods Stop (), Close () in objects for these purposes, but to trace usage of object after Close () heavily, here so appear difficultly caught bugs sometimes in deleter push objects which upon do not delete object. It too can lead to problems since there is a misunderstanding as the code (deleter hides because of type erasure) works

6

Re: shared_ptr Against all

Hello, _NN _, you wrote: _NN> Help with examples with what case ubiquitous usage shared_ptr will be to the detriment? _NN> we admit us not strongly performance concerns interest. Well, for example, we have shared_ptr <int> - if them will be much we receive doubling  storages: a single whole number on the useful data and the second on the counter of links. For example, our process of 32 bits, has ones and a half +  for the useful data, we receive the general need three + , and in 32 bits  do not pour (well so much, we will not be about these khaki with  balance 2+2 on 3+1 because it is written ones and a half + and three +, here!)

7

Re: shared_ptr Against all

Hello, Mr. Delphist, you wrote: MD> Well, for example, we have shared_ptr <int> - if them will be much we receive doubling  storages: a single whole number on the useful data and the second on the counter of links. For example, our process of 32 bits, has ones and a half +  for the useful data, we receive the general need three + , and in 32 bits  do not pour (well so much, we will not be about these khaki with  balance 2+2 on 3+1 because it is written ones and a half + and three +, here!) we Suppose and with storage there are no problems. Suffices all

8

Re: shared_ptr Against all

Hello, _NN _, you wrote: _NN> Help with examples with what case ubiquitous usage shared_ptr will be to the detriment? _NN> we admit us not strongly performance concerns interest. Yes at them one lack. In them to the programmer to be tangled even easier, than in normal links and addresses.

9

Re: shared_ptr Against all

Hello, alpha21264, you wrote: A> Hello, _NN _, you wrote: _NN>> Help with examples with what case ubiquitous usage shared_ptr will be to the detriment? _NN>> we admit us not strongly performance concerns interest. A> yes at them one lack. A> in them to the programmer to be tangled even easier, than in normal links and addresses. It is possible an example?

10

Re: shared_ptr Against all

Hello, _NN _, you wrote: A>> Yes at them one lack. A>> in them to the programmer to be tangled even easier, than in normal links and addresses. _NN> it is possible an example? An example of that? How the programmer was tangled? And how such example should look? Well here something something like that: https://rsdn.org/forum/cpp/6945378.1 the Author: uzhas Date: 26.10 12:28

11

Re: shared_ptr Against all

Hello, _NN _, you wrote: _NN> Help with examples with what case ubiquitous usage shared_ptr will be to the detriment? _NN> we admit us not strongly performance concerns interest. Here in all signatures functions shared_ptr on object. And we need to transfer itself. Well , we do enable_shared_from_this, both we transfer shared_from_this. Also we receive bad_weak_ptr an exception (or generally UB to With ++ 17). Because the method accepting this, appears, was caused from the designer or .

12

Re: shared_ptr Against all

Hello, Mr. Delphist, you wrote: MD> Well, for example, we have shared_ptr <int> - if them will be much we receive doubling  storages: a single whole number on the useful data and the second on the counter of links. Two additional pointers - on int and on the counter of links, plus two long - the size of the counter of links. MD> for example, our process of 32 bits, has ones and a half +  for the useful data, we receive the general need three + , and in 32 bits  do not pour (well so much, we will not be about these khaki with  balance 2+2 on 3+1 because it is written ones and a half + and three +, here!)

13

Re: shared_ptr Against all

Hello, Alexander G, you wrote: AG> Hello, _NN _, you wrote: _NN>> Help with examples with what case ubiquitous usage shared_ptr will be to the detriment? _NN>> we admit us not strongly performance concerns interest. AG> here in all signatures functions shared_ptr on object. And we need to transfer itself. AG> well , we do enable_shared_from_this, and we transfer shared_from_this. AG> Also it is received bad_weak_ptr an exception (or generally UB to With ++ 17). AG> Because the method accepting this, appears, was caused from the designer or . Good argument. However in big enough project yet there was no such need.

14

Re: shared_ptr Against all

Hello, XuMuK, you wrote: _NN>>> Help with examples with what case ubiquitous usage shared_ptr will be to the detriment? V>> on mind come a link cross connect. But I doubt that there it, this usage, generally is possible. XMK> for example boost:: asio encourages usage shared_prt + shared_from_this for control over lifetime , and in this case to dig in guts  a cross connect-reference or a copy shared_ptr on itself it is possible easily and easy. I as a result of ringleaders separate tests that output agents are deleted when am necessary. And sense of such perversion? What for to you the link which cannot delete itself? I still understand to make from  what-thread  on a resource and instead of clearing - to cause what-thread fclose. And here even it it is not necessary.

15

Re: shared_ptr Against all

Hello, _NN _, you wrote: _NN> However in big enough project yet there was no such need. My case: * not so big project, but rather long also it is unpredictable the developing; * In it the set of classes for the same, their relation was formed it is possible to describe patterns adapter, strategy, or places even bridge; * it to reduce Diversity difficult, business logic is in each layer, risky it is all to touch, and a layer two-three it is objectively necessary; * Flow it is directed not only deep into, but also it is reverse, and it is a little more in the sides, therefore it is a lot of observer' (). As a part of the plan of the decision of some arisen problems (with  lives of objects and usage of these observer'), many classes have been translated to the approach "shared_ptr for all". In particular, observer' whenever possible use weak_ptr, and delay such weak_ptr is identical to the formal reply. Like came, but here and there there was a problem described above: * the Lifelong subscription observer' when we want to subscribe in the designer and  in ; * adapter, but not absolutely pure when the object not only constructs to itself internal object, but also then to this internal object transfers itself. For designers both problems are solved by two-phase initialization: the present initialization is caused already after a location in shared_ptr. There it already and so almost everywhere was - for other reasons. Where was not - appeared. For  the problem only with , there is simply removed the formal reply. Without it it became possible, because see above - delay weak_ptr it already the formal reply.

16

Re: shared_ptr Against all

Hello, Vain, you wrote: XMK>> For example boost:: asio encourages usage shared_prt + shared_from_this for control over lifetime , and in this case to dig in guts  a cross connect-reference or a copy shared_ptr on itself it is possible easily and easy. I as a result of ringleaders separate tests that output agents are deleted when am necessary. V> And sense of such perversion? What for to you the link which cannot delete itself? I still understand to make from  what-thread  on a resource and instead of clearing - to cause what-thread fclose. And here even it it is not necessary. Not to supervise object lifetime manually, for example here: http://www.boost.org/doc/libs/1_53_0/do … server.cpp (sm chat_session) - while it will be live connection to live and the output agent (copies shared_ptr in ). Naturally nobody does  , but  a copy shared_ptr in any functor and to forget it to clean completely not difficult.

17

Re: shared_ptr Against all

Hello, Alexander G, you wrote: _NN>> Help with examples with what case ubiquitous usage shared_ptr will be to the detriment? _NN>> we admit us not strongly performance concerns interest. AG> here in all signatures functions shared_ptr on object. And we need to transfer itself. boost:: intrusive_ptr AG> well , we do enable_shared_from_this, and we transfer shared_from_this. This harmful perversion shared_ptr it is good for "exterior" objects. And if the object knows that store it through the counter of links the counter of links should be intrusive.

18

Re: shared_ptr Against all

Hello, vdimas, you wrote: V> boost:: intrusive_ptr the Good piece. But there there is no analog weak_ptr - resolve cycles through bare pointers itself, on the risk. And the indulgence on creation of the owning pointer from  it all the same does not give (because to create the owning pointer from  is generally a logical error).

19

Re: shared_ptr Against all

Hello, Alexander G, you wrote: V>> boost:: intrusive_ptr AG> But there there is no analog weak_ptr - resolve cycles through bare pointers itself, on the risk. , yours wek_ptr is and there is historically unreliable mechanism, decades leading spurious access violation: http://www.boost.org/doc/libs/1_65_1/bo … tr.hpp//It is not possible to avoid spurious access violations since//in multithreaded programs r.px may be invalidated at any point. Reliable implementation weak_ptr in multicontinuous programs demands already two counters of links: 1. The target counter of links of the object, allocated in additional structure in storage (superfluous new) 2. The intrusive counter of links in the most this structure, managing lifetime of additional structure. I did such model, it is absolutely reliable, but it was not pleasant to me in view of low efficiency. Therefore, the intrusive target counter , and possession undersigns at architecture level, instead of at level of subtleties of implementations. Such circuit appeared more effectively,  in case of the intrusive counter we transfer bare pointers in kach-ve parameters. Because here it is game: void some_method (const shared_ptr <A> and arg) {} And here it still the big game: void some_method (shared_ptr <A> arg) {})) AG> And the indulgence on creation of the owning pointer from  it all the same does not give AG> (because to create the owning pointer from  is generally a logical error). With  in multicontinuous programs generally it is difficult. For example, I am regular  and such game: SomeType:: ~SomeType () {Lock l (my_mutex _);...} That too is a straight line access violation for the exterior code which will expect capture of it . In general, as a result I came to the circuit of two-phase corrupting in competitive algorithms. In the first phase the object should "stop", i.e. complete generated by it (or its subsystems) flows or to unsubscribe from  other flows/services etc., and then already to fail in an one-continuous manner. It is unique that, a certain method dispose () it is necessary to cause from  the latest successor. If there the whole chain not the abstract successors, in  each of them (the logic dispose will be fulfilled once, clear business). It is clear that it is possible to create helpers  class MakeDisposable <T>: public T {...} But it is all it is necessary not to forget to use correctly, i.e., alas, sr-you of language  correctness of such things . Meanwhile there is a control in  - in  the most basic object which knows, whether has been caused dispose before corrupting or not.)) But rantajm-checks this such...

20

Re: shared_ptr Against all

Hello, vdimas, you wrote: V> Tju, yours wek_ptr is and there is historically unreliable mechanism, decades leading spurious access violation: V> http://www.boost.org/doc/libs/1_65_1/bo … ak_ptr.hpp V> V>//It is not possible to avoid spurious access violations since V>//in multithreaded programs r.px may be invalidated at any point. V> How much I see from this the code the comment concerns hypothetical implementation weak_ptr, instead of actual. V> Reliable implementation weak_ptr in multicontinuous programs demands already two counters of links: So there and so two counters, are not present? And that to additional structure in storage, it so is resolved: for shared_ptr <T> (new T) - it is inevitable for make_shared <T> () - it is not present, simply the object is deleted through a direct call  p-> ~ T (), and storage lives to last weak_ptr links.

21

Re: shared_ptr Against all

_NN> Help with examples with what case ubiquitous usage shared_ptr will be to the detriment? All is good moderately. To all the place and time. shared_ptr it is necessary to use, there, where it approaches, instead of is ubiquitous. The question is set somehow is more common. The reality is necessary. What task dares?

22

Re: shared_ptr Against all

Hello, XuMuK, you wrote: XMK> not to supervise object lifetime manually, for example here: http://www.boost.org/doc/libs/1_53_0/do … server.cpp (sm chat_session) - while it will be live connection to live and the output agent (copies shared_ptr in ). Naturally nobody does  , but  a copy shared_ptr in any functor and to forget it to clean completely not difficult. Instead of it is necessary in such cases  shared, for this purpose is weak.

23

Re: shared_ptr Against all

Hello, Alexander G, you wrote: AG> How much I see from this the code the comment concerns hypothetical implementation weak_ptr, instead of actual. V>> Reliable implementation weak_ptr in multicontinuous programs demands already two counters of links: AG> So there and so two counters, are not present? , for a long time did not look at it, from the beginning 2000.)) it is exact. A nightmare. AG> And that to additional structure in storage, it so is resolved: AG> for make_shared <T> () Syntax long turns out: boost:: make_shared <SomeType> (args))) AG> and storage lives to last weak_ptr links. Well here also quits that or it is necessary most to store weak_ptr on itself, or  basis with a terrible title: class SomeType: public boost:: enable_shared_from_this <SomeType> {}; It is all the horror flying on wings of night, as on me. Well and a problem of transmission of arguments-indexes you modestly lowered.

24

Re: shared_ptr Against all

Hello, vdimas, you wrote: V> Syntax long turns out: V> boost:: make_shared <SomeType> (args) V>)) Well is longer. But plus still exception safety in certain cases, there where with new is not present it. Therefore even I prefer with unique_ptr to write make_unique. V> Well and a problem of transmission of arguments-indexes you modestly lowered. You about Because here are game: void some_method (const shared_ptr <A> and arg) {} And here it still the big game: void some_method (shared_ptr <A> arg) {}? I generally recognize that the author so wants. Help with examples with what case ubiquitous usage shared_ptr will be to the detriment? Thus spat on additional structure in storage, or on how there these counters are made, not to mention an overhead projector on the link to the pointer. We admit us not strongly performance concerns interest. Accordingly, if there is a desire to use shared_ptr, that, probably, is also a bookmark on weak_ptr with which at usage intrusive_ptr there will be nothing to stop up. About what warned. It is clear that the approach with intrusive_ptr the code will be purer and easier, in the same way it will be even purer and easier to avoid generally whenever possible  possession.

25

Re: shared_ptr Against all

Hello, Alexander G, you wrote: AG> Accordingly if there is a desire to use shared_ptr, that, probably, is also a bookmark on weak_ptr with which at usage intrusive_ptr there will be nothing to stop up. About what warned. If it is required to "stop up" in any one place when all around sits on intrusive_ptr it is possible through through here such perversion: make_shared <intrusive_ptr <SomeType>>))