What is the solution..?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • contactmayankjain@gmail.com

    What is the solution..?

    Hi,

    Its said that one should avoid dynamic allocation of memory, as it de-
    fragment the memory into small chunks and allocation of memory is a
    costly process in terms of efficiency. So what is the best solution to
    handle to situation in which we need to allocate memory at run time.


    Regards
    Mayank Jain(Nawal)
    contactmayankja in@gmail.com
    9818390836

  • Jim Langston

    #2
    Re: What is the solution..?

    <contactmayankj ain@gmail.comwr ote in message
    news:1187626911 .559829.298860@ i38g2000prf.goo glegroups.com.. .
    Hi,
    >
    Its said that one should avoid dynamic allocation of memory, as it de-
    fragment the memory into small chunks and allocation of memory is a
    costly process in terms of efficiency. So what is the best solution to
    handle to situation in which we need to allocate memory at run time.
    using dynamic allocation of memory. use new


    Comment

    • contactmayankjain@gmail.com

      #3
      Re: What is the solution..?

      On Aug 20, 9:32 pm, "Jim Langston" <tazmas...@rock etmail.comwrote :
      <contactmayankj ...@gmail.comwr ote in message
      >
      news:1187626911 .559829.298860@ i38g2000prf.goo glegroups.com.. .
      >
      Hi,
      >
      Its said that one should avoid dynamic allocation of memory, as it de-
      fragment the memory into small chunks and allocation of memory is a
      costly process in terms of efficiency. So what is the best solution to
      handle to situation in which we need to allocate memory at run time.
      >
      using dynamic allocation of memory. use new
      How new is going to solve my problem. Are you trying to say use new
      instead of malloc for allocating memory?
      Regards
      Mayank Jain(Nawal)
      contactmayankja in@gmail.com
      9818390836

      Comment

      • =?ISO-8859-1?Q?Erik_Wikstr=F6m?=

        #4
        Re: What is the solution..?

        On 2007-08-20 18:21, contactmayankja in@gmail.com wrote:
        Hi,
        >
        Its said that one should avoid dynamic allocation of memory, as it de-
        fragment the memory into small chunks and allocation of memory is a
        costly process in terms of efficiency. So what is the best solution to
        handle to situation in which we need to allocate memory at run time.
        It depends on the situation, there is no perfect solution that will work
        in all situations. I think that the advice is rather that one should
        prefer automatic storage over dynamic when possible. However, one should
        be aware that using automatic storage is not possible in all cases, in
        fact most non-trivial applications will make use of dynamic memory,
        either directly or indirectly via containers.

        For some applications were objects of a certain kind needs to be
        allocated and deallocated frequently a pool-allocator might increase the
        performance and the effects of fragmentations is lessened.

        --
        Erik Wikström

        Comment

        • Scott McPhillips [MVP]

          #5
          Re: What is the solution..?

          <contactmayankj ain@gmail.comwr ote in message
          news:1187626911 .559829.298860@ i38g2000prf.goo glegroups.com.. .
          Hi,
          >
          Its said that one should avoid dynamic allocation of memory, as it de-
          fragment the memory into small chunks and allocation of memory is a
          costly process in terms of efficiency. So what is the best solution to
          handle to situation in which we need to allocate memory at run time.
          Dynamic allocation is the ONLY solution to allocating memory at run time
          (unless you use a language that provides garbage collection). If you have
          problems with fragmentation then the only thing you can do is smarter
          dynamic allocation, which requires knowledge of the allocation requirements
          of your application.

          Comment

          • contactmayankjain@gmail.com

            #6
            Re: What is the solution..?

            On Aug 20, 9:49 pm, "Scott McPhillips [MVP]" <org-dot-mvps-at-
            scottmcpwrote:
            <contactmayankj ...@gmail.comwr ote in message
            >
            news:1187626911 .559829.298860@ i38g2000prf.goo glegroups.com.. .
            >
            Hi,
            >
            Its said that one should avoid dynamic allocation of memory, as it de-
            fragment the memory into small chunks and allocation of memory is a
            costly process in terms of efficiency. So what is the best solution to
            handle to situation in which we need to allocate memory at run time.
            >
            Dynamic allocation is the ONLY solution to allocating memory at run time
            (unless you use a language that provides garbage collection). If you have
            problems with fragmentation then the only thing you can do is smarter
            dynamic allocation, which requires knowledge of the allocation requirements
            of your application.
            What are the smarter way of allocating memory. I know the time and all
            details about the memory requirement of my application. So how can it
            help me in improving the efficiency of my code. Can you write a sample
            code for this.
            What is pool allocator?
            Regards
            Mayank Jain(Nawal)
            contactmayankja in@gmail.com
            9818390836

            Comment

            • Zachary  Turner

              #7
              Re: What is the solution..?

              On Aug 20, 11:56 am, "contactmayankj ...@gmail.com"
              <contactmayankj ...@gmail.comwr ote:
              On Aug 20, 9:49 pm, "Scott McPhillips [MVP]" <org-dot-mvps-at-
              >
              >
              >
              >
              >
              scottmcpwrote:
              <contactmayankj ...@gmail.comwr ote in message
              >
              news:1187626911 .559829.298860@ i38g2000prf.goo glegroups.com.. .
              >
              Hi,
              >
              Its said that one should avoid dynamic allocation of memory, as it de-
              fragment the memory into small chunks and allocation of memory is a
              costly process in terms of efficiency. So what is the best solution to
              handle to situation in which we need to allocate memory at run time.
              >
              Dynamic allocation is the ONLY solution to allocating memory at run time
              (unless you use a language that provides garbage collection). If you have
              problems with fragmentation then the only thing you can do is smarter
              dynamic allocation, which requires knowledge of the allocation requirements
              of your application.
              >
              What are the smarter way of allocating memory. I know the time and all
              details about the memory requirement of my application. So how can it
              help me in improving the efficiency of my code. Can you write a sample
              code for this.
              What is pool allocator?
              Regards
              Mayank Jain(Nawal)
              contactmayankj. ..@gmail.com
              9818390836- Hide quoted text -
              >
              - Show quoted text -

              I can answer this for you. Can you put me in touch with your
              employer, so he can redirect your paychecks to me as well?

              Comment

              • Default User

                #8
                Re: What is the solution..?

                contactmayankja in@gmail.com wrote:
                Hi,
                >
                Its said that one should avoid dynamic allocation of memory, as it de-
                fragment the memory into small chunks and allocation of memory is a
                costly process in terms of efficiency. So what is the best solution to
                handle to situation in which we need to allocate memory at run time.
                Why do you think it is a concern? Has this caused problems in your
                current project?




                Brian

                Comment

                • Bo Persson

                  #9
                  Re: What is the solution..?

                  contactmayankja in@gmail.com wrote:
                  :: On Aug 20, 9:32 pm, "Jim Langston" <tazmas...@rock etmail.com>
                  :: wrote:
                  ::: <contactmayankj ...@gmail.comwr ote in message
                  :::
                  ::: news:1187626911 .559829.298860@ i38g2000prf.goo glegroups.com.. .
                  :::
                  :::: Hi,
                  :::
                  :::: Its said that one should avoid dynamic allocation of memory, as
                  :::: it de- fragment the memory into small chunks and allocation of
                  :::: memory is a costly process in terms of efficiency. So what is
                  :::: the best solution to handle to situation in which we need to
                  :::: allocate memory at run time.
                  :::
                  ::: using dynamic allocation of memory. use new
                  ::
                  :: How new is going to solve my problem. Are you trying to say use new
                  :: instead of malloc for allocating memory?

                  He is saying that you should use new (and not malloc) to allocate
                  dynamic memory, if you need to do that. If you don't need dynamic
                  memory, you shouldn't allocate any.

                  The meaning of 'avoid' is "don't do it, unless you have to", not
                  "never do it".


                  Bo Persson


                  Comment

                  • werasm

                    #10
                    Re: What is the solution..?


                    contactmayankja in@gmail.com wrote:
                    What is pool allocator?
                    Go to http://www.boost.org. They have some
                    implementations for pool allocators and explanations
                    of what it is.

                    Regards,

                    Werner

                    Comment

                    • Scott McPhillips [MVP]

                      #11
                      Re: What is the solution..?

                      <contactmayankj ain@gmail.comwr ote in message
                      news:1187629009 .605281.10930@i 13g2000prf.goog legroups.com...
                      What are the smarter way of allocating memory. I know the time and all
                      details about the memory requirement of my application. So how can it
                      help me in improving the efficiency of my code.
                      There are decades of research on this. You could start with a Google search
                      for "low fragmentation heap"

                      Comment

                      • Jack Klein

                        #12
                        Re: What is the solution..?

                        On Mon, 20 Aug 2007 16:21:51 -0000, "contactmayankj ain@gmail.com"
                        <contactmayankj ain@gmail.comwr ote in comp.lang.c++:
                        Hi,
                        >
                        Its said that one should avoid dynamic allocation of memory, as it de-
                        fragment the memory into small chunks and allocation of memory is a
                        costly process in terms of efficiency. So what is the best solution to
                        handle to situation in which we need to allocate memory at run time.
                        "It is said..." by whom? What makes you think this mysterious third
                        person source of information is correct?

                        If you do think this anonymous source is correct, ask he/she/it for
                        recommendations .

                        --
                        Jack Klein
                        Home: http://JK-Technology.Com
                        FAQs for
                        comp.lang.c http://c-faq.com/
                        comp.lang.c++ http://www.parashift.com/c++-faq-lite/
                        alt.comp.lang.l earn.c-c++

                        Comment

                        • tony_in_da_uk@yahoo.co.uk

                          #13
                          Re: What is the solution..?

                          On Aug 21, 1:49 am, "Scott McPhillips [MVP]" <org-dot-mvps-at-
                          scottmcpwrote:
                          Dynamic allocation is the ONLY solution to allocating memory at run time
                          (unless you use a language that provides garbage collection).
                          Getting there. I would argue that dynamic allocation IS - by the very
                          meaning of the word dynamic - allocation at run-time. It's not just
                          the only solution, it is indivisibly the thing itself. "garbage
                          collection" only refers to one aspect of the myriad design and
                          implementation choices for algorithms offering dynamic memory
                          management.
                          If you have
                          problems with fragmentation then the only thing you can do is smarter
                          dynamic allocation, which requires knowledge of the allocation requirements
                          of your application.
                          Precisely.

                          Mayank: what's good depends a lot on the patterns of memory usage.

                          There are a couple distinct aspects.

                          Firstly: there's how often you need to do allocations. For example,
                          if you are having trouble inserting millions of elements in a
                          container, then see if there are functions to preallocate the required
                          space rather than grow during insertions, or at least to resize more
                          aggressively (e.g. resize arrays or hash tables by x4 instead of x2
                          each time more space is needed). How much can be done depends on the
                          container: for example, linked lists aren't likely to allow any kind
                          of pre-allocation.

                          Secondly: you can decrease the time needed for the allocations you
                          really can't avoid. To do this, follow suggestions elsewhere in this
                          thread, and use a custom allocator from boost.

                          So, to work out which direction to head down, you should profile your
                          application and work out which containers are causing you trouble,
                          during what kind of operations (insert, lookup, erase).

                          Taking a step back, in your original post:
                          Its said that one should avoid dynamic allocation of memory, as it de-
                          fragment the memory into small chunks and allocation of memory is a
                          costly process in terms of efficiency. So what is the best solution to
                          handle to situation in which we need to allocate memory at run time.
                          "It's said" suggests even looking at memory allocation may be a path
                          you've started on with no clear evidence from actual profiling. Did
                          someone at work tell you "this things slow, think it's the memory
                          allocation", and ask you to fix it? Don't believe them unless you see
                          hard evidence in the form of profiling results: you'll waste a lot of
                          time.

                          Cheers,

                          Tony

                          Comment

                          Working...