Solved

Defference between calling Functions defined in same unit and different units

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need Delphi function to get Youtube video title 5 223
System restore point 4 91
Multiple image collision 13 69
tidtcpserver connection lost handle 2 70
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

914 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

16 Experts available now in Live!

Get 1:1 Help Now