I work on a program with about 50 DLLs that are loaded from one executable, it's an old organically grown program where the only rationale for creating a new DLL is that one previously didn't exist to fill a given need. (and namespaces didn't exist in Delphi so it never crossed our mind to make dll1.main.pas, dll2.main.pas or something even more unique)

What we want to do is consolidate all these DLLs into one executable, since none of them are used out of the program, there shouldn't be much of a problem. The concern my boss has is that if we did this, the memory overhead for terminal server clients would go through the roof.

So, I've stepped through enough initialization code to know that lots of stuff is done every time a DLL is loaded in to memory, but say I've got a project with about 4000 files, and 50 dlls, 10 of which are probably utilized by any one user in any one session of the program. The 50 dlls are about 2/3rds form files, if not more, but beyond that there's not a lot of other resources being loaded (only a few embedded pictures, icons, cursors, etc..). If I loaded all these files in to memory, how much memory is used per unit? how much is used per class? How do I keep the overhead down? and what is the biggest project one can reasonably expect to build with Delphi?

This tidbit won't help answering, but I think it might clarify what my boss is worried about, we currently start our program at about 18megs, normal working conditions are usually less than 40 megs, he thinks it could climb as high as 120 megs.

  • Whats the size of these 50 dll's now? Are there forms and other resources in them? Commented Sep 11, 2012 at 18:44
  • @GrandmasterB good point, that'll affect the overhead, I edited it in there. It's quite a bit, but there aren't a lot of other resources that aren't already loaded at runtime. Commented Sep 11, 2012 at 18:51
  • A single executable launched multiple times under terminal services will use the same amount of shared, and the same amount of non-shared RAM as one composed of DLLs. The only time DLLs ever save anyone memory is when they are loaded into two or more DIFFERENT main executables. Sounds like your boss is a bit Old School Like the Old School, and likes premature optimization.
    – Warren P
    Commented Sep 27, 2012 at 18:35
  • And who worries about 100,200, or 500 megs on a TERMINAL SERVER? These 64 bit Terminal Server machines run to 128 gb RAM these days.
    – Warren P
    Commented Sep 27, 2012 at 18:35
  • 1
    Microsoft stopped supporting server 2k3 on July 13, 2010. Sometimes your clients need your help determining that its time to move on.
    – Warren P
    Commented Sep 28, 2012 at 11:58

2 Answers 2


Memory usage wont be a problem for you. A couple of my Delphi apps routinely use a GB or more. So long as you are not running into the platform limits you'll be fine. I'm not sure if resources themselves are loaded from disk when the exe starts. Certainly they would be for auto-created forms. So you'll want to avoid those, and continue to create the forms manually. And free them, too.

I dont think there's a lot in the way of concrete answers for you since its really going to depend on whats in the dll's. Best is to compile everything up into a single exe and see how it looks. A single exe would certainly be easier to manage (and frankly, is one of the strengths of Delphi). The big issue is if it'd be a problem to run such large exe's on a terminal server, since you'd have multiple copies running. Ultimately it might be more cost effective to compile to a single exe and add some ram to the terminal servers if needed. On a normal desktop I dont think it'd be an issue at all.


You'll end up using fewer resources by combining all you code in a single image. You'll have one instance of the RTL rather than 50.

Not the answer you're looking for? Browse other questions tagged or ask your own question.