« first day (625 days earlier)      last day (4324 days later) » 

Ell
11:01 PM
if you have functions which require to be overriden
 
@jmlopez you make it virtual if the base class doesn't have a logical way to implement it
 
Ell
for example if you provide a useful interface where there are functions which rely on this one pure function
 
True, I like the concept of virtual functions... but, how do they affect performance?
I recently tried them, and maybe the difference in time wasn't that much (about 3 seconds)
 
@jmlopez They cause a pipeline stall, and usually cannot be inlined, but the slowdown is usually minuscule in large programs.
 
@MooingDuck, That's why... I was really hoping that they were being inlined
I have a loop that calls them
 
Ell
11:03 PM
don't prematurely optimise
 
many many times.
 
@jmlopez they can only be inlined if the new T call is in the same function, and a bunch of other restrictions
 
Ell
are you benchmarking properly?
 
@Ell, good point, I may not be since I have a random seed in my random number generator.
all this is an estimate...
 
@Ell that's kind of a silly question really. Everyone says "yes". There's a lot tat goes into benchmarking
 
Ell
11:05 PM
well i mean are you using the release build and things like that
 
@Ell and making displaying the result of some sort to be sure the compiler doesn't remove the code entirely. That's the one everyone always forgets.
 
Ell
@mooingduck it at least gets people to think
 
So wait, @MooingDuck, how can I inline virtual functions again?
 
Ell
I think (could be wrong) if you can inline the virtual call, it eliminates the point of it being virtual
 
@Ell, that's fine, all I care about is that if I have a base class A with some pure virtual function called setSize() (for instance).
and then I have a class B derived from A
I want to be able to define how B implements setSize
 
Ell
11:08 PM
yeah
 
now, when I create a function ,I can pass an A object.
and use setSize
 
Ell
but i assume there will be a C and a D as well?
 
so in this case I will be passing a B object to whatever function I want
yeah sure, there'll be C and D
and all of them will have a different way of implementing setSize
that's why virtual functions come in handy
 
Ell
no but if you have a pure virtual function it in A you cannot instantize it
 
but, whenever they are being called a lot of times in a loop
@Ell, true, you cannot instantize an A object
because it have a pure virtual function
but once you define setSize in B, C and D
 
Ell
11:09 PM
yeah sorry I didn't read far enough
 
@Ell there's a few rare cases where the compiler can figure it out
 
@MooingDuck, I would be very insterested in knowing how I can help the compiler
what can I do in my code to help it
 
@jmlopez basically there's only one situation where it can be inlined:
base* ptr = new Bimpl();
ptr->stuff();  //compiler knows it's a Bimpl still
Doesn't work if the pointer came from another function, was stored in an array, or many other details.
 
Wait, ok, so I have a pointer called ptr which points to a base object.
and this base object is of type Bimpl
so when I do ptr->stuff() it calls the stuff() function I defined for Bimpl?
the main thing here is, the compiler will inline it?
 
@jmlopez the inline declaration is a recommendation, other times, it will inline just for the fun of it.
 
11:15 PM
ok, even better...what if I have:

Bimpl obj();
obj.stuff()
and we have of course that Bimpl is derived from base
will there be any inline code here?
 
Only your compiler will know...
 
Is there any way I can ask my compiler if its doing it?
 
Ell
there won't be a virtual call there because it is not polymorphic because there are no pointers or references involved
 
@CaptainGiraffe I'm pretty sure you missed all the context, that answer is only vaguely related
 
Optimizations for speed often uses inlining for common code blocks. Study the docs real hard or look at the assembly.
 
Ell
11:17 PM
I think, ask duck
 
@jmlopez depends on where ptr was assigned, if the compiler can prove what the most derived type is
@jmlopez yeah, in that case everything can be inlined in that function
 
@MooingDuck K. [Lurk mode activated]
 
@jmlopez what compiler
@Ell you're correct
 
gcc, g++
 
though you will have to be able to read the ASM at least somewhat to tell if it's been inlined or not
woo! I now pass 1216/1748 test cases! Making progress!
 
11:21 PM
@MooingDuck, thanks for the link
Alright, I still need to be a little bit more careful on the benchmark.
Nah, screw it, virtual functions are great.
I'll sacrifice a little performance for easy coding.
That's what I'm doing with C++ after all aren't I?
 
@jmlopez yeah, when you start trying to optimize virtual calls, you're at the point where you're probably making it slower, not faster.
 
I'm still not sure what you mean by optimizing
 
Xeo
49 mins ago, by Cicada
bugs.php.net Why the subdomain?
That was a mean one.
 
All I'm doing so far is making two versions of a simple stochastic simulation. One in which I virtual functions and one in which I don't
 
@jmlopez it's a very little performance drop. If it's in the cache, it's a slowdown of about 6 instructions. On the other hand, if you read a normal variable not in the cache, it stalls for several hundred instructions.
 
Xeo
11:25 PM
room topic changed to Lounge<C++>: bugs.php.net -- Why the subdomain? [c++] [c++11] [c++-faq]
 
the one with no virtual functions seems to run a little faster than the one which does.
 
Ell
"seems" to run faster?
 
lol
yeah, like I mentioned before, I'm using a random seed
and I did several trials
in average the ones with virtual functions were running in about 23 seconds
the ones with no virtual functions were running in about 20
that's what I mean by "seems"
 
Ell
if I were you I really wouldn't worry about the performance of virtual calls
 
That's why I came here
to clear my mind from these stupid worries
 
Ell
11:27 PM
as long as you are using them for the right reasons semantically then its fine in most occasions
 
and try to start coding in a neat way
Take for instance a simple matrix class (please don't say that I'm reinventing the wheel)
 
@jmlopez also consider: how much time did you spend trying to make it go faster? How many times would you have to run the program to justify that time you spent? A hundred times?
@jmlopez heh, no such thing as a fast simple matrix class :D
 
lol
alright
 
There was a quite instructive question on branch prediction that might or might not be useful to you in the headlines just the other day. stackoverflow.com/questions/11227809/…
 
consider a not so simple matrix class
which defines how to access and how it sets the size of the matrix
I want to make this an abstract class
because later on I will like to define a matrix class which allocates memory using the new operator in C++
another derived class will use other methods
to connect it to mex files (in matlab)
or mathlink files (mathematica)
or many other type of languages that have already their memory allocation
 
Ell
11:30 PM
are you likely to mix and match these various matrix classes?
 
in this instnace I really need to make setSize a pure virtual function
well, the only time that I'll be doing mixing
is for instace the regular c++ matrix (using new operator)
and the other matrix class (say from MATLAB)
will not be mixing
but MATLAB and Mathematica will not be mixing
So, in conclusion, in this case I really need the use of pure virtual functions to make an abstract class called matrix
and then from there derive a bunch of matrix classes, each with different implementation of how it allocates memory
and how it sets its size
My only concern was about the virtual functions and the effect on performance
which after this chat I will not worry about anymore
Thank you kind people.
 
Ell
hmm I'm nit suee you're going about the resit. right
*design
 
user406009
@jmlopez An alternative way of doing this is to use templates. Then you don't need a base class. Performance probably won't change much either way though.
 
@jmlopez don't make it abstract, make it a template instead. You know the implementations at compile time
 
Oh, yes
I am using templates too
 
11:36 PM
USE TEMPLATES ALL THE TIME!!!
 
oh...
 
when you can.
 
I still can't get it, I have a combination of templates and virtual functions
but maybe I'm not thinking about it right...
 
@jmlopez you can mix and match templates and virtual functions.
Avoid virtual functions, but if you have to, you have to. Don't stress about it. Even iostreams rely very heavily on virtual functions.
 
alright @MooingDuck, I will rethink it a little bit more
maybe... just maybe I can handle everything with templates
wait no
I can't lol
 
11:39 PM
This was just a silly attempt at getting Moo to change the quite condescending subtitle, but if you can templates matches stuff at compile time. virtuals do not.
 
@jmlopez that's fine too
 
because what I want is to do ...
is to declare functions like this: `void someFunction(matrix<double>& m)
 
@CaptainGiraffe subtext?
 
so later I can do: someFunction(b) where b is of some type derived from matrix
 
template<class allocator>
void someFunction(matrix<double, allocator>& m)
 
11:41 PM
lol
I'm dumb... :D
Thank you
 
@jmlopez not dumb, thinking in templates is tricky, takes getting used to
 
@MooingDuck There's enough php bashing. We don't hit the fat kid in the schoolyard either.
 
Alright, I'm so glad I came here for a chat
thank you guys. I'm off
 
im back :)
 
user406009
11:42 PM
@CaptainGiraffe PHP is the worst heavily used language in modern times.
 
Ell
@itninja hello
 
user406009
There can never be too much PHP bashing.
 
@RMartinhoFernandes Well, maybe with subtleties but not like this.
 
Ell
@jmlopez always happy to have pleasant new members here such as yourself, bye now :)
 
@jmlopez good luck
 
11:44 PM
@CaptainGiraffe If you're talking about the PHP thing, I neither said the statement nor made it the topic, I dunno why you're calling me out
 
Ell
is "calling out" an American phrase?
 
Seriously, it's not like C++ compilers are not buggy as heck.
 
@Ell I dunno.
 
@MooingDuck If that is the case, I apologize.
 
@CaptainGiraffe I believe Cicada said it and Xeo made it the topic. :D I just starred it.
 
11:46 PM
What was the first new language feature of c++ that you found odd? Like "Hey this is not really that cool!"
For me it was auto.
I prefer typedefs
 
Monomorphic lambdas.
 
Ell
as in c++11?
 
@Ell Anytime
 
@CaptainGiraffe The first "odd" thing I found was that while(std::cin >> myint) would "freeze" if given a letter
@CaptainGiraffe auto was completely different before and after C++11
 
"auto was completely different before and after C++11" Yep a complete redefinition.
 
11:48 PM
@MooingDuck ? Are you sure?
 
Ell
well I only really know c++11
I started learning when c++0x was being talked about
 
That's the spirit.
 
@RMartinhoFernandes in most newbie programs (including mine at the time), yes
@RMartinhoFernandes wait, no, I got that wrong.
 
Ell
as a noob I'm still learning so I don't have one feature set to compare to c++11
 
11:51 PM
stupid good habits interfered with my memory
 
To clarify, auto was on par with "try to make this a register variable" back in the days. msdn.microsoft.com/en-us/library/6k3ybftz%28v=vs.80%29.aspx
 
cin >> myint;
while (myint < 0) {
     cout << "must enter a positive number!";
     cin >> myint;
} //INFINITE LOOP OH GOD WHY
 
@MooingDuck I-feel-for-you-bro.jpg
 
11:56 PM
@MooingDuck That's the one.
 
So, for endianness conversion, I'm considering various interfaces: void output(OutputIterator&, uint8_t, uint8_t), void output(OutputIterator&, uint16_t), or std::array<uint8_t, 2> convert(uint16_t) and other combinations. I can't make a choice. Request advice.
 
@RMartinhoFernandes I wouldn't go iterators, not for a value->value conversion. One would wrap iterators around the function, but not make them part of the function
I'd go with the last one.
 
@RMartinhoFernandes Curious, why do you need to do endianness conversions?
 
Serializing UTF streams. Playing around, really.
 
hmm, though it's going from one value to a array/pair, so that logic doesn't hold.
I think the second one best. The first is ambiguous
Though lord knows why you'd take my advice on anything. I'm pretty sure I'm proven stupid :D
 

« first day (625 days earlier)      last day (4324 days later) »