Solved

Defference between calling Functions defined in same unit and different units

Posted on 2004-08-05
3
223 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
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 50 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now