CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Angry Question about uninitialized memory.

    Hi, everyone!

    My STL tutorial said,

    --------
    A raw_storage_iterator enables algorithms to
    store results into uninitialized memory.
    --------

    But I do not know what means uninitialized memory.
    Who can give me an explanation of what means
    uninitialized memory? Here are two examples given
    by the tutorial. Please give me the explanation through
    the following examples.

    Example 1:

    --------
    vector<int> a (2, 5);
    vector<int> b (2, 7);
    int *c = allocate((ptrdiff_t) a.size(), (int*)0 );

    transform (a.begin(), a.end(), b.begin(),
    raw_storage_iterator<int*, int> (c), plus<int>() );

    copy (&c[0], &c[2], ostream_iterator<int> (cout, " ") );

    --------

    Example 2:
    --------
    template <class T1, class T2>
    inline void construct(T1* p, const T2& value) {
    new (p) T1(value);
    }

    int a[10] = {1, 2, 3, 4, 5};
    copy (&a[0], &a[5], raw_storage_iterator<int*, int> (&a[5]) );
    --------


    Thanks in advance,
    George

  2. #2
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468
    Anyone can help?

    George

  3. #3
    Join Date
    Apr 2001
    Location
    Germany
    Posts
    22

    Smile

    Hi!

    Uninitilized Memory is allocated space for objects, which has no objects yet.

    E.g. you create an object with new, some memory for your object is allocated and a new object will be created.

    The function "allocate" allocates only memory it creates no object. This kind of memory is called uninitilized.

    Why using a row_storage_iterator? This answer is simple. Any of the standard sequence algorithm uses assignment instead of constrction. With a row_storage_iterator you 've got a method to call the copy constructor for initialization. This way of allocation and initalisation could save time, because initialisation is often faster than assignment.

    Greetz

    Oliver

    P.S.: Sorry for my bad english

  4. #4
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Talking

    Thanks, Oliver buddie!

    George
    Originally posted by Oliver Kunst
    Hi!

    Uninitilized Memory is allocated space for objects, which has no objects yet.

    E.g. you create an object with new, some memory for your object is allocated and a new object will be created.

    The function "allocate" allocates only memory it creates no object. This kind of memory is called uninitilized.

    Why using a row_storage_iterator? This answer is simple. Any of the standard sequence algorithm uses assignment instead of constrction. With a row_storage_iterator you 've got a method to call the copy constructor for initialization. This way of allocation and initalisation could save time, because initialisation is often faster than assignment.

    Greetz

    Oliver

    P.S.: Sorry for my bad english

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