Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Defference between calling Functions defined in same unit and different units

Posted on 2004-08-05
3
Medium Priority
?
246 Views
Last Modified: 2010-04-05

Hi,

    I made two projects. In first one, from the main unit I am calling 20 different functions defined in a single unit. In second project all these 20 functions made seperated in to 20 different units. The exe size of second one is found 1KB more than that of the first one.

   1) What is the exact reason for this exe size differnce?
   2) Is there any differnce in performace between the two exes (I couln't notice any. All the 20 functions were just a showmessage popup) ? Why?

  Pls give me some valuable comments.

                                             Thanks,
                                                                            Binu.M.S



   
0
Comment
Question by:binu_emmes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Expert Comment

by:LRHGuy
ID: 11725970
Each unit that interfaces procedures necessitates making the routine "far", whereas when they are NOT interfaced, they are "near", in the same code segment. The compiler can optimize the call to near routines/procedures/functions. Interfaced procedures need some extra code, which I believe you found to be added a few more times becuase of all the extra units.

There probably is a speed difference, but it wouldn't be noticed until it was over several hundred or thousand calls to the procedure.

Just the nutshell version.
0
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 150 total points
ID: 11727942
Go to Project|Options, tabpage "Linker" and set "Map file" to "Detailed" for any of your projects. Then build that project and next to the resulting binary, you'll see a map file. If you look inside this map file, you can see which units are used, where they are located in the SINGLE codesegment and where theeir data is stored in the data segment. You will see lines like:

 Start         Length     Name                   Class
 0001:00000000 00055794H .text                   CODE
 0002:00000000 00001684H .data                   DATA
 0002:00001684 00002F79H .bss                    BSS

And this tells you where the code and data segments are. Next, you get lines like:

 0001:00000000 000050D0 C=CODE     S=.text    G=(none)   M=System   ACBP=A9
 0001:000050D0 00000174 C=CODE     S=.text    G=(none)   M=SysInit  ACBP=A9
 0001:00005244 00000B14 C=CODE     S=.text    G=(none)   M=Windows  ACBP=A9
 0001:00005D58 00000038 C=CODE     S=.text    G=(none)   M=Messages ACBP=A9
 0001:00005D90 000002C8 C=CODE     S=.text    G=(none)   M=SysConst ACBP=A9

The first four digits tell you in which segment this part of the code is located. Next you get the start position and length of the code that's put in your project. Then some information about what kind of data (code) is stored in that location and with the M=xxx you will know which unit this piece of binary belongs to.

A bit further you'll see a list of addresses of where your procedures and variables are located in the binary. And again, these addresses start with the segment ID of four digits.
Below this you'll see an overview of where your lines of code can be found in the binary. Then a list of resources included in your executable. And at the end you'll see the start address of your program.

LRHGuy is talking about near and far jumps but no... This is the old 16-bits way of thinking, where memory was still divided in multiple segments and calls were either far or near. But in 32-bits Windows you don't use many different code segments anyway. (You can, but there's no real use for it anymore.)

The growth could actually just be related to the fact that you just added another unit with a bit of code to your application. If every additional unit adds another 50 bytes to your application for it's initialization/finalization or whatever else, you will indeed notice a 1 KB (50x20) growth with 20 such units...
There's no difference in performance, though. One unit or 20 units, all function calls are just near calls...
0
 

Author Comment

by:binu_emmes
ID: 11759297

Hi,

    Thanks Workshop_Alex and LRHGuy for your comments.

                                                                     regards,
                                                                                     Binu.M.S
             
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question