IRC Log Viewer » #firebreath » 2011-08-13

IRC Nick Time (GMT-7) Message
linearray 10:08 is there a rule of thumb when I should wrap stuff in a shared_ptr, and when I should just let it be copied?
taxilian 11:08 linearray: sure; if it makes sense to copy it, copy it
if it doesn't, use a shared_ptr
any other questions? =]
linearray 11:08 when does it make sense :)
I mean, most often it doesn't hurt
taxilian 11:08 well, let me gives you some examples; if JSAPI could be copied, it'd be a real problem because the copied object wouldn't be the one that was exposed to javascript, so you'd have to do a deep copy which would be expensive both computationally and memory-wise
linearray 11:08 but I've yet to see a case where it actually makes sense
yes
taxilian 11:08 on the other hand, if you're passing a small structure that just has a bunch of ints in it then it is probably just as cheap to copy it
in fact, the shared_ptr class itself gets copied, right? =]
linearray 11:08 hehe
so I'll stick with default copy
taxilian 11:08 I usually prefer to pass things by reference or as a pointer, personally; as you say, there aren't a lot of cases where it makes more sense to copy it
but there are times when the overhead of having reference counting doesn't make sense either
only use a shared_ptr if there is no clear ownership / scope for the object
otherwise either use a stack variable or a scoped_ptr
linearray 11:08 ok thx
taxilian 11:08 or you could use a std::auto_ptr if the ownership needs to be transfered
linearray 11:08 ah nice
so a scoped_ptr is to a shared_ptr what a mutex is to a semaphore
taxilian 11:08 umm… yeah, I suppose that makes sense
scoped_ptr is just a noncopyable smart pointer that will destroy its contents when it goes out of scope
incidently there is also scoped_array and shared_array
linearray 11:08 just throwing analogies around
taxilian 11:08 for when you want to do the same thing with an array of objects
linearray 11:08 aren't arrays evil?
taxilian 11:08 lol. what do you mean?
linearray 11:08 I've been thoroughly conditioned by a myriad of c++ resources to not use arrays :)
taxilian 11:08 those resources are correct… and they are wrong, if you think they are always applicable
linearray 11:08 yes
taxilian 11:08 if you need a fixed-size array, use an array
if it's going to change, or if you don't know the size before it is passed in, often it makes sense to use a vector or similar
for example, in FireBreath we pass around a std::vector<FB::variant> all the tiem
however, if you were to need a memory buffer, I'd use a scoped_array (or shared_array) of uint8_t
because vectors aren't nearly as efficient, particularly for something like that
it all depends on what you're doing
if you are going to use a dynamic array, though, using a scoped_array or shared_array is much safer because you know that the memory will be freed
linearray 11:08 well, yeah
I'm using a vector for my socket buffer right now
taxilian 11:08 (of course, I don't know that I'd market myself as a C++ expert, but that's my experience)
linearray 11:08 and since apparently every vector implementation is backed by an array, even though it doesn't *have* to
it doesn't make much difference
taxilian 11:08 well, it might
and it might not
but one issue you could run into is that if the vector has to resize a bunch of times it has to copy the data from one to the other
which could be problematic in some cases
linearray 11:08 indeed
which is why I preallocate :)
taxilian 11:08 right; at which case you're not really any better off than using a scoped_array =]
though I guess the vector tracks the size for you
and doesn't require boost
linearray 11:08 but this socket buffer is actually a good example... I thought it didn't make much sense to copy the entire network traffic from the socket buffer to something useful for the caller, so I'm working with pointers
and this sounds like auto_ptr is the correct choice
taxilian 11:08 or shared_ptr
both would work well
auto_ptr you have to be a bit careful with; each time you copy it it transfers the ownership, which can be confusing
linearray 11:08 what does that mean technically?
when the one with ownership runs out of scope, the pointee is destroyed?
taxilian 11:08 if you assign an auto_ptr to another auto_ptr, the original auto_ptr will become null
linearray 11:08 ok
taxilian 11:08 only one references the object at a time
linearray 11:08 well, that sounds good
taxilian 11:08 it can be
linearray 13:08 out of curiosity: what browser are you using when you are not developing?
taxilian 13:08 lol. usually either Chrome, Firefox, or Safari
most often two of the three
linearray 13:08 I could pull my hair out... it's a dilemma
taxilian 13:08 probably more often than not Chrome and Firefox
linearray 13:08 chrome is nearly perfect but Flash performance is abysmal
taxilian 13:08 flash hasn't been working for me on firefox recently; not sure why
(I'm on a mac, btw)
linearray 13:08 me too
btw thanks for the visual assist suggestion... I bought that and it makes my life quite a bit easier
taxilian 14:08 it's pretty nice, isn't it? nirvdrum donated to FireBreath to pay for mine; it's saved me probably at least days if not weeks of time since then
linearray 14:08 I'm surprised that MS isn't providing something like that... I remember a time when C++ was the only language MS cared about, but I guess today it's all .NET
taxilian 14:08 they've been moving back in the C++ directly recently
most .net stuff they seem to be pushing to silverlight
linearray 14:08 I'm very curious how that will work out
taxilian 14:08 yeah; it'll be interesting to watch
linearray 14:08 there has been quite an outcry when they presented the windows 8 UI
taxilian 14:08 they're probably trying to regain some of the ground they're losing to apple
linearray 14:08 based on html5 etc.
don't know if they released anything since then
taxilian 14:08 I haven't been really paying attention
nirvdrum 14:08 taxilian: Did Georg ever get his? Actually, I haven't seen him around in a while. Is he still active on the project?
taxilian 14:08 I sent him the money for it, but I told him he could use it as he wanted; he did enough for the project to earn it
he hasn't been real active for quite awhile
he still helps me now and again when I have a particularly tricky problem
nirvdrum 14:08 Gotcha.
taxilian 14:08 last I heard he was focussing on a degree
(not sure if it's a rough equiv of masters or if higher)
how is mogotest going?
nirvdrum 14:08 It's keeping me busy, that's for sure.
Always could be doing better though.
taxilian 14:08 well, there is a lot to be said for even staying afloat
nirvdrum 14:08 We're finally making review lists people are putting out, so that's been a big help exposure-wise.
taxilian 14:08 nice
nirvdrum 14:08 My fun project for the last day and a half has been pushing everything through a squid proxy.
taxilian 14:08 hehe. is that so you can track what is going on with ajax calls and such?
well, I gotta go help my wife for awhile. g'luck all
nirvdrum 15:08 Sorry. Was away. The matter is more that our customers want to filter out the traffic, so it's best if it originates from a known IP block. EC2 makes that rather difficult.
Squid will let me speed up some of my tests by cutting down on external network traffic, too.
Oh, and the other problem we have is a surprisingly large number of people can't handle the number of concurrent we throw their way. So this reduces that load.