Re: Sorry, I forgot about copy constructor (was: Re: C++ problem)
Omer Zak [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Replying to myself, because I forgot one more point: From what I remember about C++, you need also a copy constructor in this case, In this case a copy constructor is not invoked. because you strive to copy a value to a variable (and in this special case, the value is a constant instance of a class). On Sat, 29 Jan 2005, Omer Zak wrote: On Sat, 29 Jan 2005, Shachar Shemesh wrote: Hi all, Here is a small program for your viewing pleasure: class a { public: explicit a(int param); What is the meaning of 'explicit' declaration? Is this a C++ keyword which was added since I learned C++? a operator= ( a that ); }; How are the variables in this class declared (if there are any variables at all)? int main() { a var1(3); var1=a(5); return 0; } Somewhat surprisingly, this does not compile: g++ -Wall -gtestcompile.cc -o testcompile testcompile.cc: In function `int main()': testcompile.cc:12: error: no match for 'operator=' in 'var1 = a(5)' testcompile.cc:5: error: candidates are: a a::operator=(a) make: *** [testcompile] Error 1 There are two things that can make it compile. One is to add a const at the operator= definition, and the other is to use an explicit variable (i.e. - not a temporary one). The reason for this failure seems to be that g++ treats temporary variables as consts. I see neither reason nor logic for this decision, however. Why can't I modify temporary variables if I so wish? Don't they have a well definedlife span (until the end of the statement) for a reason? My guess is that the language allows the temporary a(5) to be compiled as a constant and stored in read-only part of the program. Consider what you would have wished to happen if you had used complex(0.707,0.707) instead of your own a. --- Omer [snip] -- Alex Vinokur email: alex DOT vinokur AT gmail DOT com http://mathforum.org/library/view/10978.html http://sourceforge.net/users/alexvn = To unsubscribe, send mail to [EMAIL PROTECTED] with the word unsubscribe in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]
Re: C++ problem
Shachar Shemesh [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I'm wondering WHY temporary implicit variables should be considered const. It's clear that the compiler does consider them like that. [snip] See http://groups-beta.google.com/group/comp.lang.c++/browse_frm/thread/1a6f14442620c98e http://www.groupsrv.com/computers/viewtopic.php?t=111003sid=d321ba1cca3434d3354a918fccbd9ebb -- Alex Vinokur email: alex DOT vinokur AT gmail DOT com http://mathforum.org/library/view/10978.html http://sourceforge.net/users/alexvn = To unsubscribe, send mail to [EMAIL PROTECTED] with the word unsubscribe in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]
Re: C++ problem
Shachar Shemesh [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi all, Here is a small program for your viewing pleasure: class a { public: explicit a(int param); a operator= ( a that ); }; int main() { a var1(3); var1=a(5); return 0; } Somewhat surprisingly, this does not compile: g++ -Wall -gtestcompile.cc -o testcompile testcompile.cc: In function `int main()': testcompile.cc:12: error: no match for 'operator=' in 'var1 = a(5)' testcompile.cc:5: error: candidates are: a a::operator=(a) make: *** [testcompile] Error 1 There are two things that can make it compile. One is to add a const at the operator= definition, and the other is to use an explicit variable (i.e. - not a temporary one). The reason for this failure seems to be that g++ treats temporary variables as consts. I see neither reason nor logic for this decision, however. Why can't I modify temporary variables if I so wish? Don't they have a well defined life span (until the end of the statement) for a reason? [snip] Foo(5) is constant, so 'Foo operator= (const Foo)' is applied. -- foo.cpp : BEGIN -- #include iostream #include cassert using namespace std; struct Foo { explicit Foo(int) {} Foo (const Foo) {assert (0);} // Copy constructor is not invoked Foo operator= (Foo that) { cout __PRETTY_FUNCTION__ endl; if (!(that == this)) /* Do something */ ; return *this; } Foo operator= (const Foo that) // 'const' has been added { cout __PRETTY_FUNCTION__ endl; if (!(that == this)) /* Do something */ ; return *this; } }; int main() { Foo var1(3); Foo var2(4); var1 = Foo(5); // Foo operator= (const Foo that) is applied, because Foo(5) is constant var1 = var2; // Foo operator= (Foo that) is applied return 0; } -- foo.cpp : END -- Compilation Run : BEGIN -- $ gpp --version gpp.exe (GCC) 3.4.1 [---omitted---] $ gpp -W -Wall foo.cpp // No errors/warnings $ ./a.exe Foo Foo::operator=(const Foo) Foo Foo::operator=(Foo) -- Compilation Run : RUN -- Alex Vinokur email: alex DOT vinokur AT gmail DOT com http://mathforum.org/library/view/10978.html http://sourceforge.net/users/alexvn = To unsubscribe, send mail to [EMAIL PROTECTED] with the word unsubscribe in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]
Re: Various performance problems
Shachar Shemesh [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] [snip] The questions: a. Does anyone have a recommended benchmarking tool? I found this page (http://lbs.sourceforge.net/), but I'd really rather not start messing around with each and every one of those until I find the one I like. If anyone here has prior experience, I'd love it if you could share. [snip] Look at C/C++ Program Perfometer (Tool for measuring comparative performance of the C/C++ code). http://groups.google.com/groups?selm=bm9216%24jvo98%241%40ID-79865.news.uni-berlin.de Perhaps it is not exactly what you are looking for, but maybe it might help you. = Alex Vinokur mailto:[EMAIL PROTECTED] http://mathforum.org/library/view/10978.html news://news.gmane.org/gmane.comp.lang.c++.perfometer = = To unsubscribe, send mail to [EMAIL PROTECTED] with the word unsubscribe in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]
Re: getting process memory usage
Title: Message "moses" [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]... Hi all - I want to get some information on the memory usage of processes like total size and number of pages in real memory i know that "cat statm" under a process in the / proc give the answer i want to what function in the kernel code (probably in fs/proc/proc_misc.c ) this commands calls to. thanks it would help me a lot. Look at getrusage() : http://www.die.net/doc/linux/man/man2/getrusage.2.html ========= Alex Vinokur mailto:[EMAIL PROTECTED] http://mathforum.org/library/view/10978.html news://newsgmane.org/gmane.comp.lang.c++.perfometer =