« first day (299 days earlier)      last day (4651 days later) » 

1:01 AM
Hello @TonyTheTiger
oops, gotta run. Later,
 
 
4 hours later…
5:10 AM
I woke up.
 
user457812
Waking up is a terrible thing.
 
5:46 AM
It's like child birth.
 
6:06 AM
Only worse.
 
6:52 AM
Nah.
If you wake up on your own, it is not that bad.
Worse if it is your alarm clock.
And even worse is a crying child at 3 am. :)
 
 
1 hour later…
8:08 AM
ScopedResource<int> fd(fopen(fn), fclose);
ScopedResource<void*> buffer(malloc(n), free);
^ Such a utility class could be nice.
 
8:23 AM
Create one?
 
#define BOOST_RESULT_OF_USE_DECLTYPE
#include <boost/utility/result_of.hpp>

struct functor {
    template<class T>
    T operator()(T x)
    {
        return x;
    }
};

typedef boost::result_of<
    functor(int)
>::type type;
what is the purpose of result_of there?
does it just get what functor returns?
I'm confused as what result_of is supposed to achieve
 
8:49 AM
@TonyTheTiger yeah, it's an attempt at deducing the return type of a function or functor in C++03
made unnecessary by 0x and decltype, of course
but I believe Boost then just reimplements result_of to use decltype internally
 
9:07 AM
oh cool thx
 
Morning.
 
9:21 AM
of course, it was impossible to implement robustly in C++03, so they came up with a result-of protocol for how you were supposed to "hint" at what your return type was. So decltype solved a lot of problems there
 
9:57 AM
I find it rather sad that C++ originally had auto type deduction in the eighties, but Bjarne was forced to take it out again... would have made many plumbing classes unnecessary.
(It wouldn't have helped with function return types, though. But maybe Bjarne would have extended the language with decltype much sooner.)
 
@FredOverflow oh really? I didn't know that
 
@jalf You should put "The Design and Evolution of C++" on your birthday wish list then ;)
He was forced to take it out because of C incompatibility.
auto i = some_short; defines i as a short in C++0x but as an int in C (because of the implicit int rule).
Was "implicit int" ever dropped from C? When?
 
@FredOverflow yeah, I should. :)
 
Sadly, it was written before the STL was envisioned. But that keeps the book "small".
 
10:16 AM
Hmm I thought C loved char and not int.
 
@ÓlafurWaage No... in facht, sizeof('a') is sizeof(int) in C.
 
10:48 AM
anybody ever built a project with boost.jam through vs2010?
 
11:00 AM
nope
 
11:21 AM
Meh, mod removed my answer with all the comments, before I could read responses.
 
morning
 
This is ridiculous, why bother removing comments if you're going to remove the post anyway.
Now I can't laugh at more derp.
Not to mention the answer shouldn't be removed, but whatever.
 
11:35 AM
hi @deadMG and hi @cat
refering to this question I still have some doubts
 
What about the question @munish ?
 
No just a sec
 
From your question and comments, it seems that you understand that you can have a const data member, but you don't understand what purpose(s) it can serve. Is that correct ?
 
If you have a piece of data that is constant for the life-time of an object, and is unique to the object, then it could sense to have it as a non-static const data member. However, can you think of an example where you would need this, and have you ever seen it either. Moreover, if you encapsulate the data member, it cannot be modified by code external to the class anyways and marking a non-static variable as const doesn't improve performance either.
 
Let me show you an example :
 
11:40 AM
So, it probably isn't very useful and certainly not common to have non-static const data members
 
Let's say you have a class Res which encapsulates some resource (lets say a file identifier)
Every instance of Res has its own file identifier and this one cannot change.
To ensure that this private file identifier don't change during the lifetime of your Res instance, you can declare it const.
It makes sense because the only way to first set it is in the constructor(s) of Res and since it is never meant to change, you can declare it const as to avoid potential programming errors.
 
that's not terrifically useful, because now your class isn't assignable
and const_cast is undefined behaviour in that situation, so you can't just const_cast it away
 
I don't see why this would be a problem.
 
well, it would be a problem because many classes require assignability, such as std::vector
 
Usually my resources classes inherit from boost::noncopyable anyway
 
11:44 AM
and there's no reason conceptually why it shouldn't be assignable
 
I understand his(ere's point) by the way thanks
 
you can do an inner class trick to make it assignable and guarantee const access in member functions
 
I don't get you : copying a handle to a file for example is often not possible
and has no meaning
 
a handle to a file is just a pointer and can be copied however you like
 
if you want to share it, just encapsulate it within a shared_ptr or something
 
11:45 AM
and Win32 provides a DuplicateHandle function
 
Not if you consider your class has exclusive ownership on the resource
 
I see- so I should have to dynamically allocate on the heap because I want to store in a vector?
 
Who said I was talking about Windows ? ;)
 
you said that duplicating a handle isn't possible and makes no sense
 
Sorry but I really don't understand you. Who said something about the heap ?
 
11:46 AM
it's just a pointer- duplicating it is both possible and makes plenty of sense, just like any other pointer
 
shared_ptr is just an option
 
how else am I going to store it in a shared_ptr?
 
"within a shared_ptr or something" ;)
 
what equivalent something do you have in mind?
 
please note the "or something"
 
11:47 AM
hai
 
if I'm wanting to store as a value, then there's no choice here
 
Nothing public I'm afraid.
 
if I want to store as a reference, then I'm going to have to go to the heap
 
So to you, a resource can always be copied ?
 
I didn't say that- but a const member cannot be moved into either
nor swapped
 
11:48 AM
I don't see why this would be a problem either.
Not all classes have to be movable or swappable.
 
it's a problem because they're both totally valid operations to perform, extremely useful to do, and you're disallowing them because you're too lazy to write a few extra lines in a template that will instantly solve the problem
and in return, you're going to make me, the user of your class, waste my life heap allocating it and managing the lifetime
it's a dumb idea to restrict the users of your class unless you have a damn good reason
 
because I'm too lazy or because they don't make any sense in my particular situation ? :)
 
what resource do you have in mind that can't be moved or swapped?
 
I can't believe how rude you are when you actually know nothing about my particular needs and constraints.
A resource of mine named "Foolabaloo". Does it help ?
 
you were the one talking about a file handle
or a private identifier
both of those can be moved or swapped
 
11:51 AM
Yes. A file handle on my Foolabaloo file system.
 
I see
so basically, you don't actually have any real examples
 
I do.
See my Foolabaloo file system code.
 
link
 
It's private :) (How nice is that)
 
I see
so, you don't actually have any examples to share with the class
and pretty much every other file system in the world has completely movable handles
 
11:53 AM
Not Foolabaloo sadly
 
ok
 
well, the rest of us will move on and work in systems that actually exist
 
whats new @DeadMG?
 
@TonyTheTiger Trying to fix my last evar grammar problem
but Bison doesn't like me :P
 
11:55 AM
The worst thing is that I really don't understand why you get so harsh.
 
boost.build doesn't like me
@ereOn don't worry about it, that's @DeadMG.... :)
 
You can say the wisest things in the world, but as long as you say other people are "idiots" you won't get any positive result.
 
you're not getting a positive result either
 
I do.
 
you're in here telling that guy to do something which is wrong
 
11:57 AM
@DeadMG like DeadMG++? ;)
 
and then making up some justification
 
Because I will carefully think about what you said while I'm pretty sure that with your attitude, you won't even remeber what I said.
 
@ereOn it's always a good idea to provide some code example...
 
and that guy is going to go off and make his life harder
because of you, because you said something that is not true
 
@TonyTheTiger: Absolutely. I was just pissing DeadMG a little bit because I found his attitude surprising and disapointing.
Because I said something that you don't believe is true.
 
11:58 AM
@jalf I don't advise people to do things in C++ which are wrong because of the theoretical existence of DeadMG++
well, you haven't exactly proved it to be true
 
theoretically, I can understand that :)
 
Nor have you proved it wrong.
 
burden of proof is on you
 
How unlucky am I so :(
 
even if you did have such a system that was real, then it would be in such the massive minority that it would be in all practicality irrelevant to the discussion
 
11:59 AM
Would it help if I took the burden of proof on me?
 
Ok so you are right. const data members never serve any purpose whatsoever.
Especially not when dealing with resources.
 
in C++0x, you can get the benefits of const data members and movability/swappability in one go
 
in C++03, you'll just have to trust yourself to never do anything stupid with it
 
12:00 PM
@ÓlafurWaage lol
 
Also : I saw a pink elephant flying around my house yesterday. Your turn to prove it wrong.
 
Check out the recommends (except the nsfw one if you're at work)
 
burden of proof is on you, you're claiming it to be true
however, I'm not going to claim that it isn't true
 
Well in this case I lied. I did not see any elephant sadly.
 
merely that it would be incredibly dumb of me to waste my own time assuming that you did
 
12:02 PM
Or incredibly open-minded !
 
@DeadMG: did you make any progress with your allocator?
 
What a change in biology that would be.
 
@KerrekSB No. The only answers posted do not resolve the issue.
 
@DeadMG Are you using MSVC? I got it to work fine in GCC...
 
that guy in the comments said that trivial use worked fine for him on MSVC10 too
ok, problem solved
I started off allocating 80kb, so I upgraded to 800kb
but forgot to actually resize the vector to that much :P
 
12:07 PM
Ahh
 
when I fixed that up, it worked if I increased the capacity to 1MB
what the hell kind of hash map takes over 800kb of memory for 20k ints?
that's like, 1,000% memory overhead
 
You might just suffer from not reclaiming freed memory
 
I would buy that, except I never free any memory
only ever insert to the hash map
although I guess if they use vector internally, then they would have to resize
 
The hash map itself may be moving things around. Are you tracking calls to the deallocator?
 
no
and moving things around shouldn't result in calls to the allocator and deallocator
 
12:12 PM
I like how Incredibuild just sums up the speed of all CPUs participating in the build
"54.5 GHz"
 
ok
I added some tracing
apparently, the map allocated 459600 bytes, deallocated 37440 bytes
in only 4 deallocator calls
 
Done. It's clear that you're failing to reclaim moved memory
I set the memory to 80kB and insert 10000 elements, and I get a failure after 2579 inserts.
 
uh, I don't think so, 460kb vs 37kb
yes, I'm failing to reclaim the memory, but that's not a significant dent in the amount allocated
 
The amount of memory that's being freed increases linearly, so the total amount lost is quadratic.
 
still
 
12:17 PM
Ah. But deallocation also happens at exponentially increasing intervals.
 
I think it's interesting that I still can't match the C# Dictionary time
even guaranteeing always contiguous memory and very favourable allocation times
and pre-allocating all memory
I've still got 0.7ms to the recorded C# time of 0.32ms
 
Hm, but this is hardly useful if you're so wasteful with memory, is it?
 
I have a more specific purpose for it in mind that alleviates the problem
 
I see. Well, the allocator is not the problem at least :-)
 
do you think that the JIT could be cheating?
like looking ahead to the loop and expanding the hash map beforetime?
 
12:22 PM
In C#? No idea. That sounds pretty complicated, but it's possible.
 
I find it hard to believe that it could be that much faster
considering how cheap I've made my memory allocator
without performing that kind of trick
 
What's the problem anyway - is C# outperforming you on a particular use case?
 
some guy posted a benchmark saying that C#'s Dictionary was much faster than his C++ unordered_map
I'm trying to prove that it's not
hopping down in time to 0.525 is a very long way from the OP's original about 10ms
and yes, it kind of bothers me that I can't beat the C# time
0.45ms to 0.53ms
on the other hand
it makes me feel very happy, because the metaprogramming tricks I have lined up in "DeadMG++" can automatically perform such memory optimizations
 

« first day (299 days earlier)      last day (4651 days later) »