LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-09-2006, 10:24 AM   #1
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87
Function call overhead (C programming)


Looking at my program ive noticed that im extensivly useing alot of functions to split the program up and im wonding if im incuring a performance hit because of the number of functions im calling from other functions. Is function overhead still a problem or does GCC and other moden compilers allevate this ?

Also does the number of file descriptors count as a program is run or does the Operating system get one back when the stream is closed ?
 
Old 10-09-2006, 02:52 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
In general, the compiler makes decisions about how to reduce function call overhead. You can force the issue with inline function calls, which ask the compiler to inline the function code.

You shouldn't worry about performance unless you know there is an issue. For example, have you profiled your code and found a big bottleneck? or are you running in an arm environment where resources are very limited?

File descriptors are "counted" by the kernel when a file is opened or closed. COuld you tell us what you mean by "get one back"?
 
Old 10-09-2006, 03:23 PM   #3
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
"Premature optimization is the root of all evil." If the code works elegantly and understandably with all the function calls in, best to keep it that way until you know you've got a problem.

File descriptors are issued on a per-process basis. Whenever you close a file in your program, it's descriptor becomes available for use again, so as long as you close files when you're done with them you should be OK. (Unless you are expecting to read from a million different files simultaneously.)
 
Old 10-09-2006, 04:49 PM   #4
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Original Poster
Rep: Reputation: 87
Ahh ok I wasent really worried that my program was slow at all considering its rather basic in its function and nasty in it's current form. Its going to be rewritten but for a passing intrest I was just curious if people really worried about it anymore with C code. As for the file descripters yes thank you and no im not opening millions of files just the same one over and over again. (this is part of the nasty part )
 
Old 10-09-2006, 05:51 PM   #5
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by taylor_venable
"Premature optimization is the root of all evil."
But what is being optimised? If code is being optimised for maintainability then go for it, make it as optimally maintainable as possible.

Hence yes, break it down and go for those functions.

Last edited by graemef; 10-09-2006 at 05:53 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to call function in kernel vishalbutte Programming 10 02-07-2006 02:50 AM
How to call another function from a function? geminigal Programming 4 04-21-2005 10:41 PM
No Matching Function for Call ! vipinsharma Programming 2 07-05-2004 01:58 PM
how to call function?? harpal Programming 3 04-29-2003 05:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration