ShellExecute Memory usage?

This is a discussion on ShellExecute Memory usage? within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I'm using ShellExecute to open a file, and my memory usage almost doubles when I do -from about 1.5mb ...

  1. #1
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459

    ShellExecute Memory usage?

    Hello,

    I'm using ShellExecute to open a file, and my memory usage almost doubles when I do -from about 1.5mb to 3mb, and doesn't go back down.

    I call it like,

    Code:
    ShellExecute(NULL, "open", "C:\test.html", NULL, NULL, SW_SHOWNORMAL);
    I've looked at MSDN, and it doesn't say anything about closeing or freeing handles, what am I doing wrong? Is it supposed to work like this anyway?

    Code:
    Windows XP
    MinGW
    gcc -W -Wall -ansi -pedantic -O2 -mwindows -o launch launch.c -lkernel32 -luser32 -lshell32
    Thanks in advance

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What are we comparing here? The extra amount of executable file, the amount of memory your application uses whent it's running or something else?

    I don't expect ShellExecute to be a "lean" function, it's a quite powerfull function that does a lot of work for you (like identifying which executable goes with which extension, finding where that executable lives, etc). It may well drag in quite a few other functions that in turn drag in a few more functions, all of which bloats your code - but you'd have to add quite a bit of your own code if you wanted to do this "By hand" - probably not as much, because you could limit the function to specifically doing the things your app needs, but still a fair bit of code.

    --
    Mats

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Hmm, k thanks...

    It was the amount of memory it used at run time after ShellExecute was called, in comparison when it wasn't called

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It sounds a little bit excessive, I have to say - but I haven't looked at what ShellExecute does - it wouldn't surprise me if it calls all sorts of functions that build lists of extensions and paths, that will use up a noticable amount of memory (aside from the functions themselves that obviously add to the size at runtime).

    --
    Mats

  5. #5
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    It does indeed call a massive bunch of functions. It seems to initialize the shell class which is used in every shell function and never released because it is used in other shell functions and is trying to save time by not reinitializing the class.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  6. #6
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    So really, If I want to use it I have to live with the extra mem usage? Thing I hate about it, it's not just ShellExecute() it's a few other functions, CreateDialog() for example, and the memory usage continues to increase but never goes down!? I do close all the handles where required, so it's not a mem leak or anything.

    But if I call subsequent ShellExecute()'s the memory usage remains the same, (doesn't climb again) - so I guess it's not too bad.

    Thanks matsp & maxorator

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mutex and Shared Memory Segment Questions.
    By MadDog in forum Linux Programming
    Replies: 14
    Last Post: 06-20-2010, 04:04 AM
  2. Problems with shared memory shmdt() shmctl()
    By Jcarroll in forum C Programming
    Replies: 1
    Last Post: 03-17-2009, 10:48 PM
  3. Memory allocation/reallocation
    By magda3227 in forum C Programming
    Replies: 10
    Last Post: 07-04-2008, 03:27 PM
  4. Structs vs. Classes, Memory Usage
    By CrazyNorman in forum Game Programming
    Replies: 2
    Last Post: 07-17-2005, 05:43 PM
  5. Memory Usage
    By ghe1 in forum Linux Programming
    Replies: 0
    Last Post: 03-18-2002, 08:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21