Page 14 of 20
Re: C++/C programming discussion
Posted: Fri Oct 01, 2010 3:49 pm
by Scott
Matthew wrote: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.
How have you pinpointed it down to a memory leak then? I mean, that would be a hard thing to figure out would it not? I don't do much with low level memory allocation.
Re: C++/C programming discussion
Posted: Fri Oct 01, 2010 3:51 pm
by Matthew
I used the MallocDebug performance tool with the OSX SDK.
Re: C++/C programming discussion
Posted: Fri Oct 01, 2010 3:55 pm
by Scott
Matthew wrote:I used the MallocDebug performance tool with the OSX SDK.
Ah. I don't have any debugging tools but I do have techniques...like most programmers. But like I said, I don't really do much low level memory allocation work.
Re: C++/C programming discussion
Posted: Fri Oct 01, 2010 4:07 pm
by Matthew
Have you used C++'s new and delete? That's an alternative way to perform memory allocation. C++ has nothing to replicate realloc() though. With malloc is simpler to view the memory block as completely un-assigned to any type so you have a little more control on how you use it. You could add several pieces of data in your own way using a void pointer I suppose. I've never done that.
Re: C++/C programming discussion
Posted: Fri Oct 01, 2010 4:17 pm
by Scott
Matthew wrote:Have you used C++'s new and delete? That's an alternative way to perform memory allocation. C++ has nothing to replicate realloc() though. With malloc is simpler to view the memory block as completely un-assigned to any type so you have a little more control on how you use it. You could add several pieces of data in your own way using a void pointer I suppose. I've never done that.
I know of them and how to implement them, but have never used them on a real project.
Re: C++/C programming discussion
Posted: Fri Oct 01, 2010 7:18 pm
by Matthew
Argh! Even after fixing memory leaks, CPython is faster.... Why?

Re: C++/C programming discussion
Posted: Fri Oct 01, 2010 8:11 pm
by Scott
Matthew wrote:Argh! Even after fixing memory leaks, CPython is faster.... Why?

Wikipedia wrote:CPython is the default, most-widely used implementation of the Python programming language. It is written in C. In addition to CPython, there are two other production-quality Python implementations: Jython, written in Java, and IronPython, which is written for the Common Language Runtime, as well as several experimental implementations.[1]
CPython is a bytecode interpreter. It has a foreign function interface with several languages including C, in which one must explicitly write bindings in a language other than Python.
I think that sums up why

Re: C++/C programming discussion
Posted: Fri Oct 01, 2010 8:15 pm
by Matthew
CPython is an interpreter. That should automatically make it slower.
I've made my program 3 times faster. I'm going to continue adding features and I'll do further optimisation later.
Re: C++/C programming discussion
Posted: Fri Oct 01, 2010 8:22 pm
by Scott
Matthew wrote:CPython is an interpreter. That should automatically make it slower.
I've made my program 3 times faster. I'm going to continue adding features and I'll do further optimisation later.
Ya, but it's still a high level language, making it
almost automatically slow.
Oh, and how do you get program speeds?
EDIT:
But CGI has been obsoleted by today Web standards so I would think having a Web-enabled language (PHP, Perl, Python etc) to wrap your C++ program would be a better choice.
So, how do you wrap a language? I know what this means just not how to implement (I think I know what it means).
Re: C++/C programming discussion
Posted: Sat Oct 02, 2010 3:11 pm
by Matthew
I was using a timer performance tool. It will slow it down a tiny bit. I'll use time.h for final tests or maybe a POSIX.
Wrap a programming language? I suppose what you wanted to do depends on the languages being used. If you wanted to run a C++ program on a webserver I think you could use the exec PHP command is it?
Re: C++/C programming discussion
Posted: Sat Oct 02, 2010 3:45 pm
by Scott
Matthew wrote:I was using a timer performance tool. It will slow it down a tiny bit. I'll use time.h for final tests or maybe a POSIX.
I will look for some.
"time.h" is a **** to use. It's not really complex, just the functions/classes/ect are so anti-elegant that it's a real eye sore to work with.
Matthew wrote:Wrap a programming language? I suppose what you wanted to do depends on the languages being used. If you wanted to run a C++ program on a webserver I think you could use the exec PHP command is it?
The quote I previously displayed was from a C++ forum. I didn't even know you could get C++ code on a webserver but I figured you might know (instead of starting a new thread over there). I don't even know if it's really worth it, just wondered if it was possible.
EDIT: Are there any other coding tools you use outside your IDE? I have never used any before but I assume there are some that would be a benefit to me.
Re: C++/C programming discussion
Posted: Sat Oct 02, 2010 4:03 pm
by Matthew
I use just the xcode tools for OSX and iphone development. I've used Editra for web-scripting.
I think getting C++ code on a server depends on the server and host.
Re: C++/C programming discussion
Posted: Sat Oct 02, 2010 4:07 pm
by Scott
Matthew wrote:I use just the xcode tools for OSX and iphone development. I've used Editra for web-scripting.
I think getting C++ code on a server depends on the server and host.
I haven't really checked out the tools available with my IDE...I should probably check that out. I use Code::Blocks with MinGW as the compiler.
Re: C++/C programming discussion
Posted: Sat Oct 02, 2010 4:20 pm
by Matthew
XCode has something called instruments which has many debug and performance tools.
Re: C++/C programming discussion
Posted: Sat Oct 02, 2010 5:10 pm
by Scott
Would you recommend using the sort method? Or making your own? I can make an sorting algorithm but man is it difficult...