comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <jrcarter@acm.org>
Subject: Re: When shoul Pragma Inline be used?
Date: Sun, 23 Feb 2003 18:07:21 GMT
Date: 2003-02-23T18:07:21+00:00	[thread overview]
Message-ID: <3E590DC1.5000005@acm.org> (raw)
In-Reply-To: slrnb5hmr5.5bu.randhol+news@kiuk0152.chembio.ntnu.no

Preben Randhol wrote:
> 
> I just wonder when one should use Pragma Inline and when one should not
> use it. If somebody could give some tips/links it would be very helpful.
> 
> Example:
> 
>    package body Settings is
> 
>       function Filename
>          return String
>       is
>       begin
>          return To_String (Current_File_Settings.File_Name);
>       end Filename;
> 
>       procedure Set_Filename
>          (Name : String)
>       is
>       begin
>          Current_File_Settings.File_Name := To_Unbounded_String (Name);
>       end Set_Filename;
> 
>    end Settings;
> 
> Here is makes sense to add Pragma Inline (Filename); ? But what about
> the Set_Filename (Name : String)? Should this also be Inline?

Inline allows you to indicate that you are willing to accept potentially 
larger executable size and increased module coupling in exchange for the 
speed increase of eliminating subprogram calls.

If you inline these subprograms, it's because you are using them, or 
think they may someday be used, in situations where the overhead of the 
subprogram call is unacceptable.

Since you're using Unbounded_String, it's unlikely that these 
subprograms would be acceptable in such situations with or without inlining.

A general rule I learned is: Inline small subprograms if your program 
has tight time constraints. "Small" is not precisely defined; you have 
to decide how many statements is too many. Some compilers will 
automatically inline calls to small subprograms. Such compilers must 
have a precise definition of "small", probably based on the size of the 
object code.

At 1 statement each, I would think these subprograms meet any reasonable 
definition of "small". Whether your program has tight timing constraints 
you don't say. It won't hurt to inline these subprograms, but I doubt it 
will help noticeably, either.

-- 
Jeff Carter
"Spam! Spam! Spam! Spam! Spam! Spam! Spam! Spam!"
Monty Python's Flying Circus




  parent reply	other threads:[~2003-02-23 18:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-23 14:33 When shoul Pragma Inline be used? Preben Randhol
2003-02-23 17:26 ` Bobby D. Bryant
2003-02-23 21:05   ` tmoran
2003-02-23 18:07 ` Jeffrey Carter [this message]
2003-02-23 22:00   ` Robert A Duff
2003-02-24  9:29   ` Preben Randhol
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox