Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to find out if a file is loaded in memory?

How to find out if a file is loaded in memory?

Scheduled Pinned Locked Moved C / C++ / MFC
c++performancetutorialquestion
22 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D dliviu

    Hello! Let's say I load a "data.bin" file in dinamic memory using a program. Now, can I by means of C++ code, find out using another program, if a file called "data.bin" is loaded in memory? Thanks!

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #5

    What are you trying to accomplish? This sounds like an instance of the XY problem[^].

    D 1 Reply Last reply
    0
    • L Lost User

      What are you trying to accomplish? This sounds like an instance of the XY problem[^].

      D Offline
      D Offline
      dliviu
      wrote on last edited by
      #6

      Well yes, it is a XY problem. :) When I'm opening a txt file from an application which I made I want to open another instance of this application with the file opened in it. So I don't want to load all the dlls and bins again, but just point to them in the memory (because the files were already loaded by the application which was first opened). I want to do this because I cannot make the application a MSDI one, because it's to hard to do for me.

      L S 2 Replies Last reply
      0
      • D dliviu

        Well yes, it is a XY problem. :) When I'm opening a txt file from an application which I made I want to open another instance of this application with the file opened in it. So I don't want to load all the dlls and bins again, but just point to them in the memory (because the files were already loaded by the application which was first opened). I want to do this because I cannot make the application a MSDI one, because it's to hard to do for me.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #7

        I don't think you can interfere much with how images (executables, not bitmaps) are loaded, but they're partly shared anyway. Don't ask me for too much detail, I'm not very familiar with what exactly windows does with images and/or memory mapped files. That's all much too complex for such a goal anyway - just look into MDI, it'll be simpler.

        1 Reply Last reply
        0
        • D dliviu

          Hello! Let's say I load a "data.bin" file in dinamic memory using a program. Now, can I by means of C++ code, find out using another program, if a file called "data.bin" is loaded in memory? Thanks!

          J Offline
          J Offline
          jschell
          wrote on last edited by
          #8

          Why do you think it matters if it was loaded twice?

          D 1 Reply Last reply
          0
          • J jschell

            Why do you think it matters if it was loaded twice?

            D Offline
            D Offline
            dliviu
            wrote on last edited by
            #9

            It will matter because it takes 15 seconds for the app to start.

            J 1 Reply Last reply
            0
            • D dliviu

              It will matter because it takes 15 seconds for the app to start.

              J Offline
              J Offline
              jschell
              wrote on last edited by
              #10

              DLiviu wrote:

              It will matter because it takes 15 seconds for the app to start.

              You know that there are ways to mitigate that right?

              D S 2 Replies Last reply
              0
              • J jschell

                DLiviu wrote:

                It will matter because it takes 15 seconds for the app to start.

                You know that there are ways to mitigate that right?

                D Offline
                D Offline
                dliviu
                wrote on last edited by
                #11

                No, there aren't.

                J 1 Reply Last reply
                0
                • D dliviu

                  No, there aren't.

                  J Offline
                  J Offline
                  jschell
                  wrote on last edited by
                  #12

                  DLiviu wrote:

                  No, there aren't.

                  I guess the number of times I have done it and countless others are just fantasy.

                  D 1 Reply Last reply
                  0
                  • J jschell

                    DLiviu wrote:

                    No, there aren't.

                    I guess the number of times I have done it and countless others are just fantasy.

                    D Offline
                    D Offline
                    dliviu
                    wrote on last edited by
                    #13

                    You say there are ways to make this files load faster? I guarantee you that in this case there are no ways. Loading has already been optimized to the max.

                    J 1 Reply Last reply
                    0
                    • D dliviu

                      You say there are ways to make this files load faster? I guarantee you that in this case there are no ways. Loading has already been optimized to the max.

                      J Offline
                      J Offline
                      jschell
                      wrote on last edited by
                      #14

                      DLiviu wrote:

                      You say there are ways to make this files load faster?

                      What I said was "mitigate"="Make less severe, serious, or painful"

                      1 Reply Last reply
                      0
                      • C CPallini

                        You cannot. Without hacking, you can't read memory of other processes.

                        Veni, vidi, vici.

                        S Offline
                        S Offline
                        Stephen Hewitt
                        wrote on last edited by
                        #15

                        Is calling ReadProcessMemory[^] hacking? It would no doubt end up that way if the OP tried to use it to solve his problem.

                        Steve

                        C 1 Reply Last reply
                        0
                        • D dliviu

                          Well yes, it is a XY problem. :) When I'm opening a txt file from an application which I made I want to open another instance of this application with the file opened in it. So I don't want to load all the dlls and bins again, but just point to them in the memory (because the files were already loaded by the application which was first opened). I want to do this because I cannot make the application a MSDI one, because it's to hard to do for me.

                          S Offline
                          S Offline
                          Stephen Hewitt
                          wrote on last edited by
                          #16

                          Each process has it's own address space so, in general, it's not possible to just run another instance and "point to them in the memory". If you're worried about DLL's and such beging loaded twice I'd leave the management of virtual memory up to the OS, it's smart enough to map the same physical page into multiple processes when possible.

                          Steve

                          D 1 Reply Last reply
                          0
                          • J jschell

                            DLiviu wrote:

                            It will matter because it takes 15 seconds for the app to start.

                            You know that there are ways to mitigate that right?

                            S Offline
                            S Offline
                            Stephen Hewitt
                            wrote on last edited by
                            #17

                            Find out what's really taking the time instead of guessing (I'm willing to bet incorrectly).

                            Steve

                            1 Reply Last reply
                            0
                            • S Stephen Hewitt

                              Each process has it's own address space so, in general, it's not possible to just run another instance and "point to them in the memory". If you're worried about DLL's and such beging loaded twice I'd leave the management of virtual memory up to the OS, it's smart enough to map the same physical page into multiple processes when possible.

                              Steve

                              D Offline
                              D Offline
                              dliviu
                              wrote on last edited by
                              #18

                              Are you sure of this? In what operating system? I have Win XP and I can tell you for sure that this is not happening because when I open a second app it takes as much time as the first one for all the files and dlls to load. Maybe in higher operating systems all apps point to the same adress in memory but not in XP.

                              S 2 Replies Last reply
                              0
                              • S Stephen Hewitt

                                Is calling ReadProcessMemory[^] hacking? It would no doubt end up that way if the OP tried to use it to solve his problem.

                                Steve

                                C Offline
                                C Offline
                                CPallini
                                wrote on last edited by
                                #19

                                Stephen Hewitt wrote:

                                Is calling ReadProcessMemory[^] hacking?

                                Definitely not. It simply means Carlo wasn't aware that Microsoft gently provides such a function :-O.

                                Veni, vidi, vici.

                                1 Reply Last reply
                                0
                                • D dliviu

                                  Are you sure of this? In what operating system? I have Win XP and I can tell you for sure that this is not happening because when I open a second app it takes as much time as the first one for all the files and dlls to load. Maybe in higher operating systems all apps point to the same adress in memory but not in XP.

                                  S Offline
                                  S Offline
                                  Stephen Hewitt
                                  wrote on last edited by
                                  #20

                                  Yes, XP included. I'd guess what you think is taking the time is not the real culprit.

                                  Steve

                                  1 Reply Last reply
                                  0
                                  • D dliviu

                                    Are you sure of this? In what operating system? I have Win XP and I can tell you for sure that this is not happening because when I open a second app it takes as much time as the first one for all the files and dlls to load. Maybe in higher operating systems all apps point to the same adress in memory but not in XP.

                                    S Offline
                                    S Offline
                                    Stephen Hewitt
                                    wrote on last edited by
                                    #21

                                    You say it's taking 15 seconds to start up, this gives plenty of time to break into it 5 or so times with a debugger and get some stack traces to see what it's really up to.

                                    Steve

                                    D 1 Reply Last reply
                                    0
                                    • S Stephen Hewitt

                                      You say it's taking 15 seconds to start up, this gives plenty of time to break into it 5 or so times with a debugger and get some stack traces to see what it's really up to.

                                      Steve

                                      D Offline
                                      D Offline
                                      dliviu
                                      wrote on last edited by
                                      #22

                                      Okay, I will do that. Thanks.

                                      1 Reply Last reply
                                      0
                                      Reply
                                      • Reply as topic
                                      Log in to reply
                                      • Oldest to Newest
                                      • Newest to Oldest
                                      • Most Votes


                                      • Login

                                      • Don't have an account? Register

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • World
                                      • Users
                                      • Groups