Initialization and Memory

Discussion in 'C++' started by Chris Forone, Jun 12, 2012.

  1. Chris Forone

    Chris Forone Guest

    Hello,

    if i write code like this:

    #include <vector>

    int main()
    {
    float big[] =
    {
    1.0f, 2.0f, 3.0f
    };

    std::vector<float> v(big, big + sizeof(big) / sizeof(big[0]));
    }

    are the floats twice in memory (one time from the literals, one time as
    copies in the vector)? do compilers free initialisation memory after
    initialization?

    thanks for your short answer,
    chris
     
    Chris Forone, Jun 12, 2012
    #1
    1. Advertising

  2. On 6/12/2012 1:40 AM, Chris Forone wrote:
    > if i write code like this:
    >
    > #include <vector>
    >
    > int main()
    > {
    > float big[] =
    > {
    > 1.0f, 2.0f, 3.0f
    > };
    >
    > std::vector<float> v(big, big + sizeof(big) / sizeof(big[0]));
    > }
    >
    > are the floats twice in memory (one time from the literals, one time as
    > copies in the vector)? do compilers free initialisation memory after
    > initialization?


    Most likely. Unless it isn't so.

    Those are implementation details. If you need to know what any specific
    compiler/library combination produces, look at the assembly code.

    V
    --
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Jun 12, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JKop
    Replies:
    10
    Views:
    990
  2. Matthias Kaeppler
    Replies:
    2
    Views:
    470
    Victor Bazarov
    Jul 18, 2005
  3. Jess
    Replies:
    23
    Views:
    971
  4. Replies:
    5
    Views:
    2,065
    Arne Mertz
    Mar 26, 2009
  5. Taras_96
    Replies:
    3
    Views:
    610
    Michael Tsang
    Oct 30, 2009
Loading...

Share This Page