Page 13 of 20

Re: C++/C programming discussion

Posted: Wed Sep 29, 2010 7:10 pm
by Matthew
It's not always as simple as that. Doing lots of if tests is also more inefficient and will require more CPU cycles because they are redundant. Many people use flags but they are redundant waste of memory and CPU cycles.

Re: C++/C programming discussion

Posted: Wed Sep 29, 2010 8:57 pm
by Scott
Matthew wrote:It's not always as simple as that. Doing lots of if tests is also more inefficient and will require more CPU cycles because they are redundant. Many people use flags but they are redundant waste of memory and CPU cycles.
That's not much of an argument considering that these days decent processors usually start at 2.0GHZ and that is WAAAAY more than enough to handle a bunch of if statements.

Re: C++/C programming discussion

Posted: Thu Sep 30, 2010 3:32 pm
by Matthew
That's no way to think. Also weren't we discussing PIC chips.

Re: C++/C programming discussion

Posted: Thu Sep 30, 2010 3:37 pm
by Scott
Matthew wrote:That's no way to think. Also weren't we discussing PIC chips.
I thought we had gone back to console applications again. Because, personally, for console apps memory management and CPU cycles aren't bothering me because of the power of a computer. The app would have to contain lots of loops to bog down any computer (at the console level).

Re: C++/C programming discussion

Posted: Thu Sep 30, 2010 4:46 pm
by Matthew
It's all relative. Powerful processors can run inefficient programs fast but you could run them even faster if they were efficient. Fast processors are no excuse to slack on software.

Re: C++/C programming discussion

Posted: Thu Sep 30, 2010 4:50 pm
by Scott
Matthew wrote:It's all relative. Powerful processors can run inefficient programs fast but you could run them even faster if they were efficient. Fast processors are no excuse to slack on software.
Well I don't purposely write terribly inefficient software. I was just saying that I don't necessarily worry my self silly over small things but often go back and fix some stuff afterwards. I'm not exactly a literal guy, but I can see the confusion.

Oh, and I never had to use that if statement to break idea before, it was just something I thought up to counter act your point. I still don't feel it's that big of a hog though.

Re: C++/C programming discussion

Posted: Thu Sep 30, 2010 4:57 pm
by Matthew
It adds up. If you were using loops often and there was very simple arithmetic being fone with it, the if tests could take a reasonable amount of processing time relative to everything else. It accumulates with further inefficiencies.

I think it's a good habit to avoid redundant data and processing where possible. Even if it's small, it helps the habit and can add up to make a program reasonably faster.

Re: C++/C programming discussion

Posted: Thu Sep 30, 2010 5:37 pm
by Scott
Matthew wrote:It adds up. If you were using loops often and there was very simple arithmetic being fone with it, the if tests could take a reasonable amount of processing time relative to everything else. It accumulates with further inefficiencies.
Well I'm sure in a situation where someone would use my provided code, a different solution could also work.
Matthew wrote:I think it's a good habit to avoid redundant data and processing where possible. Even if it's small, it helps the habit and can add up to make a program reasonably faster.
Well ya :)-

Oh, and in case you skipped over it, or ignored it ( :( ) I found a cool "programming" language: processing.org I put programming in quotes for a reason. It's a fairly neat thing nonetheless. And no, it's not a joke language.

Re: C++/C programming discussion

Posted: Thu Sep 30, 2010 5:44 pm
by Matthew
The language is weird though.

Re: C++/C programming discussion

Posted: Thu Sep 30, 2010 5:52 pm
by Scott
Matthew wrote:The language is weird though.
I was expecting a more robust answer from you, but yes, yes it is :lol:

I think it was to teach programming to people who are more visual. Personally it screws me right up. Regardless, it's a neat language and I plan on fooling around with it a bit in case I find a solid use for me.

Re: C++/C programming discussion

Posted: Thu Sep 30, 2010 7:15 pm
by Matthew
Why not just create a library for another language with functions like make_funky_circle()?

Re: C++/C programming discussion

Posted: Thu Sep 30, 2010 8:22 pm
by Scott
Matthew wrote:Why not just create a library for another language with functions like make_funky_circle()?
Me? Because I don't know how to do that. Them? I have even less of an idea.

Re: C++/C programming discussion

Posted: Fri Oct 01, 2010 3:38 pm
by Matthew
Yes, them.

My converter library has a memory leak. The leak happens constantly about 1MB a second. Since it's constantly reallocating more and more memory all the time, it slows down a lot also.

I can't get accurate readings on the performance gain vs CPython until this is sorted.

http://stackoverflow.com/questions/3840 ... realloc-im

Re: C++/C programming discussion

Posted: Fri Oct 01, 2010 3:39 pm
by Scott
A memory leak is when an allocated piece of memory isn't set free correct?

Re: C++/C programming discussion

Posted: Fri Oct 01, 2010 3:46 pm
by Matthew
Not necessarily, it can simply be memory which is allocated too much.

In this case, that is what is happening. Something is being reallocated as it should be and is constantly growing when nothing needs to grow so much.