Anonymous
PO
Anonymous
why did you write i-->0 and how did you understand that?
i-- > 0 i.e. check if the current value of i is greater than 0 while decrementing i. this way i inside the for loop starts at row - 1 and ends at 0 instead of starting at row and ending at 1. but the value that is tested in the condition starts at row and ends at 1 (fails when 0).
PO
Anonymous
Anonymous
I want to create small game in c
Anonymous
And i do it but one problem in that game
Anonymous
Anonymous
.
Wisenky
Dima
Patrick
Hi, all, could someone give me some pointers into reducing the size of this C++ code? I'll be adding more operations, such as bitwise, which end up being triplicated.
I feel there might be an option using ASM?
Alex
hi. what do you mean size of code? lines of code or ram usage?
Alex
just add additional functions for hassign, isfloat, default case
Patrick
Patrick
It will be a good practise for me to see how I can apply those practises to other parts of my codebase too
Patrick
as it's a VM, it has to operate with multiple different types of data frequently
Patrick
Because I feel it could be boiled down to three conditionals: the operation, the 32bits for the result, and which function to call for the value
Patrick
and the operation doesn't change between values so I'd like to optimise it
Alex
are you looking for performance optimization or just decreasing number of code lines?
Patrick
I suppose both
Patrick
And as I said it would be a good learning opportunity for me
Patrick
Anything above a g++ level 1 optimisation is unavailable to me at the moment
Alex
1. to decrease code lines: I would add 3 functions for each type of operation
2. to optimize performance: you should use profiler and get bottleneck
Patrick
I'm unsure how the functions would look like?
Patrick
Oh, three functions
Patrick
How would that be an improvement over the switch?
Alex
first function for isFloat case etc
Patrick
Really I'd like to do away with the switch
Patrick
op is constant
Alex
Patrick
why?
Because it's switching on a constant
Alex
I can`t understand your reason, but you can use unordered_map<op, function> instead of switch
Patrick
It's nice to know unordered_map exists at least, but
Patrick
this is already quite a performant function, but I'm wondering how I can avoid switching on a const
Anonymous
Patrick
Hmmm, this sounds interesting
Patrick
I haven't looked into these concepts before
Patrick
Because I don't mind duplication in the binary
Patrick
Yes, I don't mind it - it's fine
Anonymous
templates are compile time. so if a condition is not satisfied during compile time, the part related to it never makes it into the binary
Patrick
Patrick
Essentially it's the += -= *= etc which is constant
Patrick
Would I be able to invoke those operators through templates perhaps?
Patrick
Patrick
It's the operators that are the problem really
Patrick
I know that they are all discreet machine operations, that's why I thought perhaps an ASM route would help
Patrick
basically I'd love to be able to do
if (isFloat)
dResult OP_HERE v.d32c();
else if (hasSign)
sResult OP_HERE v.s32c();
else
uResult OP_HERE v.u32c();
Anonymous
Patrick
Mmmm
Anonymous
Mmmm
but you could do
function(lhs) += function(rhs)
function(lhs) -= function(rhs)
...
Patrick
perhaps hypothetically D_OP S_OP U_OP
Anonymous
and make function point to .d32c(), .s32c(), or .u32c() depending on type
Patrick
Patrick
Patrick
Mar!o
Mar!o
Use computed goto i'ts much faster than a switch statement
@unchanted
Anyone CS bachelor in this in this group?
Anonymous
@unchanted
I mean can i discuss some of my queries in this group
Of course that would be regarding to c++ but that maybe of college level
@unchanted
Or on an elementary level
Anonymous
@unchanted
klimi
Ok thanks 👍
And you can use offtopic group for non-c/c++
Mood of
Hello
abhi3700
Hello!
Let's say there are 2 functions func1, func2 defined inside a class1.
Now while defining func1outside the class, i have to use func2, now should i directly parse func2 or class1.func2 ??
@unchanted
how to know whether we have to use '->' or 'this' keyword?
olli
olli
this is a pointer to the object, e.g. on which a non-static function is being called. You need to use it when you want to access the object.
-> accesses the member of a pointer (you can also write (*ptr). )
@unchanted
olli