CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Aug 2011

    static vs dynamic array

    I was just curious if there is a performance difference (e.g access time, speed, ...) between allocating static memory vs dynamic memory?
    For example, if am reading data from a file, and storing them inside a huge buffer, what would be the differences between storing these data inside a static buffer vs a dynamic one?


  2. #2
    Join Date
    Jul 2005

    Re: static vs dynamic array

    The only speed difference should in the allocation/deallocation; access times should be equivalent. For a static array allocation/deallocation is nearly instant, for a dynamic array (I hope you use std::vector instead) a call to new[]/delete[] is required, the performance of which is not always the same, but always slower than for a static array. The unpredictability of performance for dynamic arrays can also be a reason to prefer static arrays in real-time systems.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  3. #3
    Join Date
    Aug 2011

    Re: static vs dynamic array

    Okay Thanks. It makes sense

  4. #4
    Join Date
    Apr 2000
    Belgium (Europe)

    Re: static vs dynamic array

    not quite.
    ALl dynamic arrays work off a pointer pointing to some allocated bit of memory.
    This is an extra level of indirection that isn't there when using a fixed array. This will also have a small effect on performance.

Tags for this Thread

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.