Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: About memory usage...

  1. #1

    About memory usage...

    When I create a simple application like:

    [pascal]program SmallApp;

    function MessageBoxA(HWND: Cardinal; Msg,Title: pChar; Flags: Cardinal): Cardinal; stdcall; external 'User32.dll';

    begin
    MessageBoxA(0,'Hello from small app.','Small App',0);
    end;[/pascal]

    The executable is 6 kb, which is fine... But when I run the program, why an earth is takes 3 MB ram? This is as much as full VCL apllication uses when one form is created. For example Notepad takes only about 70 kb memory. Is there any way I can reduce memory usage?

  2. #2

    About memory usage...

    Not sure? Just guessing at a possible solution here, but did you unselect all the debug options before you compiled it? By the way what program are you using to monitor the memory usage.
    My DGDev forum pascal syntax highlight settings:
    <br />[background=#FFFFFF][comment=#8080FF][normal=#000080]
    <br />[number=#C00000][reserved=#000000][string=#00C000]

  3. #3

    About memory usage...

    Yes, I have unselected all debug features and tried to compile with optimization on and off, but it still reserves huge amount of memory.

    I also created program that doesn't use MessageBox, it only has infinite repeat loop and when I look in XP's task manager, the program have 31 handles created, but none of those handles are created by my code... There are also some GDI and User objects. I suppose System unit's initialization section has something to do with this.

    I tried to make my own system unit, which doesn't contain anything than plain unit defination. I know that I can't use RTL procedures like Move, Delete etc with this unit. After I replaced the delphi's own system.dcu with my own, the compiler only gave me error message "Can't find unit system.pas"

  4. #4

    About memory usage...

    3 megs does seem a lot of memory for a messagebox, even under Windows...

    Some of the handles you mentioned might be for things like the standard input/output that are set up in system.pas. I'll investigate that later today, since it's the kind of thing I enjoy.

    I've had the same problem as you trying to get the RTL to compile. If you check in dcc32.exe, you'll see strings for various units - I think it's embedded into the compiler. If that's the case then things will get very annoying.

    I think I might post on one of the Borland newsgroups later to see what the concensus is. It seems stupid to supply the RTL source but not let you change it!

    Btw, what Delphi version and do you have the RTL source code?
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  5. #5

    About memory usage...

    I have Delphi6 and I have all RTL sources, even system.pas. But system unit's code has some strange stuff in it and it's not compileable.

    For exaple procedures such as Inc,Dec,Break,Continue etc. are not actually procedures because they are not called. "Inc" will eventually be compiled as "inc eax" or "add eax,?" CPU instruction if you look into CPU window.

  6. #6

    About memory usage...

    Yeah - IIRC, they're described as "compiler magic" functions. I think that the compiler directly copies the values, and it's hardcoded into dcc32.exe. There must be some stuff that can be removed - at the very least, some of the initialization section (which will get run behind-the-scenes). :?

    Hey, a guy has to have hope, right?
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  7. #7

    About memory usage...

    Those functions are special indeed, I tried to use the same structure as used in the read function for optional parameters, but the compiler broke my try down too, so it seems they are treated differently by the compiler...
    Do it by the book, but be the author!
    <br />
    <br />Visit the Lion Productions website at:
    <br />http://lionprod.f2o.org

  8. #8

    About memory usage...

    I think it would be possible to change execution starting address in PE header, so that program starting point would point to statement that is right after "begin" in program's main unit. Then the system unit wouldn't allocate that 3 MB chunk.

  9. #9

    About memory usage...

    I think that this isn't something to be very concerned about. Why? The memory usage doesn't seem to scale very much as the application's size increases.

    I've just written a test app that uses MSXML components, a Memo component, a couple of buttons, and a treeview. This program creates a DOM structure in memory, and displays structure in the treeview. All in all, it uses about 4.8 MB.

    If I were you, I wouldn't be too concerned with a 3 MB memory footprint, but that may be because I come from a Java background

  10. #10

    About memory usage...

    You're right, it's not a big thing. But I'm just wondering why 7 kb program requires so much memory. For example if I want to write a program that runs in system tray and it's running in background all the time, it's very stupid to waste memory and decrease system performance. When the program could as well survieve with 20 kb.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •