Results 1 to 3 of 3

Thread: Memory size

  1. #1

    Memory size

    System: Windows
    Compiler/IDE: Delphi 5
    Libraries/API: None

    When you go in "Project" menu and click the "Information for.." item
    a dialog box appears and give some statistics about Code size and data size.

    How can I get in my program the Data size as a function result??

    I mean I'm looking for a function, for example:

    function GetProjectDataSize: integer; that returns the memory size of the static structures that are used.
    Last edited by Jimmy Valavanis; 30-03-2012 at 04:58 PM.

  2. #2

    Memory size

    nothing like that exists, however you could get that info from the PE header by looking for .data/DATA section and if you find it look at SizeOfRawData member...

  3. #3

    Memory size

    I've made the next function:

    Code:
    const
    IMAGE_NT_OPTIONAL_HDR32_MAGIC = $10b;
    type
    PPESectionHeaderArray = ^TPESectionHeaderArray;
    TPESectionHeaderArray = array[0..$FFFF] of TImageSectionHeader;
    
    function I_GetSizeOfRawData(fname: string = ''): LongWord;
    var
    f: file;
    PEHeaderOffset, PESig: Cardinal;
    EXESig: Word;
    PEHeader: TImageFileHeader;
    PESectionHeaders: PPESectionHeaderArray;
    PEOptHeader: TImageOptionalHeader;
    i: integer;
    begin
    if fname = '' then
    fname := ParamStr(0);
    filemode := 0;
    {$I-}
    assign(f, fname);
    reset(f, 1);
    BlockRead(f, EXESig, SizeOf(EXESig));
    if EXESig <> $5A4D {'MZ'} then
    begin
    close(f);
    result := 0;
    exit;
    end;
    seek(f, $3C);
    BlockRead(f, PEHeaderOffset, SizeOf(PEHeaderOffset));
    if PEHeaderOffset = 0 then
    begin
    close(f);
    result := 0;
    exit;
    end;
    seek(f, PEHeaderOffset);
    BlockRead(f, PESig, SizeOf(PESig));
    if PESig <> $00004550 {'PE'#0#0} then
    begin
    close(f);
    result := 0;
    exit;
    end;
    BlockRead(f, PEHeader, SizeOf(PEHeader));
    if PEHeader.SizeOfOptionalHeader <> SizeOf(TImageOptionalHeader) then
    begin
    close(f);
    result := 0;
    exit;
    end;
    BlockRead(f, PEOptHeader, SizeOf(PEOptHeader));
    if PEOptHeader.Magic <> IMAGE_NT_OPTIONAL_HDR32_MAGIC then
    begin
    close(f);
    result := 0;
    exit;
    end;
    GetMem(PESectionHeaders, PEHeader.NumberOfSections * SizeOf(TImageSectionHeader));
    BlockRead(f, PESectionHeaders^, PEHeader.NumberOfSections * SizeOf(TImageSectionHeader));
    result := 0;
    for i := 0 to PEHeader.NumberOfSections - 1 do
    result := result + PESectionHeaders[i].SizeOfRawData;
    close(f);
    {$I+}
    if IOResult <> 0 then
    result := 0;
    end;

    I use the SizeOfRawData member, but the function returns the size
    of code plus the size of const data of program (I suppose).

    What I need is a function to return all the data size (i.e. not only tables
    that are initialized).

    E.g.

    var tbl1 = array[1..1024*1024] of LongWord; // <- not constant!!!

    Any ideas??
    Last edited by Jimmy Valavanis; 30-03-2012 at 04:58 PM.

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
  •