How: multiple program instances sharing same data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Zytan

    #16
    Re: How: multiple program instances sharing same data

    What counts here is the Private part, so you should watch the Private
    Process counters for your process. The GC heap is part of the private
    memory
    of a process, the amount of memory you consume from the GC heap depends
    on
    your allocation scheme, the more and the larger the objects you create
    ,the
    larger the GC heap grows and consequently the larger your Private bytes.
    Process Explorer shows a graph of history of private bytes, so this is
    very useful.

    Zytan

    Comment

    • Zytan

      #17
      Re: How: multiple program instances sharing same data

      I could probably reduce the stack space by half or more, I bet,
      without causing problems, I forgot about that. I'll have to see how I
      can change that.
      >
      You can't do this for the 3 threads created by the run-time, you can only
      change the default size of the stack of the threads you create explicitely.
      This page http://www.thescripts.com/forum/thread229335.html says

      "The stack is set to an arbitrarily small value when the program is
      first loaded. The stack then grows on demand to meet the needs of the
      thread. This is implemented by placing a page with PAGE_GUARD access
      at the end of the current stack. When your code causes the stack
      pointer to point to an address on this page, an exception occurs. The
      system will commit your desired page. The 1M was the default maximum
      stack size that can be commit."

      So, it looks like it wouldn't make any difference, anyway.

      Zytan

      Comment

      • Willy Denoyette [MVP]

        #18
        Re: How: multiple program instances sharing same data

        "Zytan" <zytanlithium@g mail.comwrote in message
        news:1195063458 .174344.38190@i 38g2000prf.goog legroups.com...
        I could probably reduce the stack space by half or more, I bet,
        without causing problems, I forgot about that. I'll have to see how I
        can change that.
        >>
        >You can't do this for the 3 threads created by the run-time, you can only
        >change the default size of the stack of the threads you create
        >explicitely.
        >
        This page http://www.thescripts.com/forum/thread229335.html says
        >
        "The stack is set to an arbitrarily small value when the program is
        first loaded. The stack then grows on demand to meet the needs of the
        thread. This is implemented by placing a page with PAGE_GUARD access
        at the end of the current stack. When your code causes the stack
        pointer to point to an address on this page, an exception occurs. The
        system will commit your desired page. The 1M was the default maximum
        stack size that can be commit."
        >
        So, it looks like it wouldn't make any difference, anyway.
        >
        Zytan
        >

        This article is based on the V1.X Framework and not quite correct.
        In V2, you can create threads with other stack sizes than the 1MB default,
        but the threads created before your program runs will still be 1MB max. Of
        course you can edit the PE file header and set all stacks to a lower value
        for the whole process, but that's in general a bad idea, CLR application
        are quite stack "hungry".
        Note that stack space is always pre-committed for CLR threads, this is *not*
        the case for unmanaged threads which is what the above describes.


        Willy.


        Comment

        • Zytan

          #19
          Re: How: multiple program instances sharing same data

          This article is based on the V1.X Framework and not quite correct.

          Ok, good catch.
          In V2, you can create threads with other stack sizes than the 1MB default,
          but the threads created before your program runs will still be 1MB max.
          My program makes a few threads, and they shouldn't need 1 MB each, so
          I should reduce their sizes.
          Of course you can edit the PE file header and set all stacks to a lower value
          for the whole process, but that's in general a bad idea, CLR application
          are quite stack "hungry".
          Ok, so any thread stacks that I can't easily change (without hacking
          the .exe) are better off left as-is... good enough.
          Note that stack space is always pre-committed for CLR threads, this is *not*
          the case for unmanaged threads which is what the above describes.
          Oh, wait, so for CLR threads that start implicitly, their stack memory
          are commited. Fine. But, for threads that *I* make, with Thread(),
          their stack space is NOT commited? That means I don't need to worry
          that they are 1 MB each, since that memory won't actually be committed
          unless they really use it, right?

          Thanks very much as always, Willy

          Zytan

          Comment

          • Zytan

            #20
            Re: How: multiple program instances sharing same data

            Is NGEN "Native Image Generator"?
            >
            Yep.
            Use it whenever you need to run several instances of the same application,
            it produces sharable code images (see above). You can't live without it when
            running on Terminal Server for instance.
            >
            I still haven't tried this, yet, and I will when I find some time, and
            report back here.
            I tried it, and it worked. Didn't change a lot, but it reduced memory
            usage by about 5%. I found this page useful in describing how to use
            it: http://www.codeproject.com/useritems/Ngen.asp

            Zytan

            Comment

            Working...