CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2005
    Posts
    1,030

    If I run the same program twice under linux

    what section would be shared in the memory? Thanks.

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: If I run the same program twice under linux

    I'm not entirely sure about Linux.
    But eligible sections would be:

    - code
    Typically in a copy on write scenario. Assuming it's located at it's prefered load address, which would usually be the case for executables and "maybe" for dynamic libraries, and assuming there is no such thing active as load address randomization.
    - const data
    again in a copy on write scenario (see above)
    - embedded resources
    assuming they don't have literal pointers but use offsets, otherwise, again, copy-on-write see above
    - import and export tables
    - address fixup table



    If you cannot guarantee prefered load address...

    It is possible to write code that does not have pointers and instead uses offsets only (this doesn't mean you can't use C++ pointers). There are compilers that help you do this, without compiler support, this is "difficult" and will require a considerable amount of effort on your part.
    There is no benefit to doing this if you can guarantee prefered load address.

    It is possible to organize your const data in such a way to avoid copy-on-write effects. For 'flat' C/C++ data this is fairly easy.
    It is somewhat problematic for literal strings, you will need to convert them all to a single unit and access all string access indirectly by offset/index. The same is true for any other structures accessed by address.
    While this takes effort on your part, it actually results in a better/cleaner approach to const data, and depending on needs, may actually have significant performance boosts as well.

  3. #3
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: If I run the same program twice under linux

    Pretty sure that "If I run the same program twice under linux", then nothing will be shared in memory.
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  4. #4
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: If I run the same program twice under linux

    One strike up for windows and one strike down for Linux if that's the case.

    In a system where you could be running the same executable image multiple times (system dll's are obvious examples), but also consider things like terminal services where dozens of users may be running the same executables at the same time.
    ALlowing the system to share sections of the images means a huge boost to overal memoryusage.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured