Click to See Complete Forum and Search --> : Question about uninitialized memory.


George2
February 14th, 2003, 06:06 AM
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

George2
February 15th, 2003, 01:12 AM
Anyone can help?

George

Oliver Kunst
February 18th, 2003, 05:03 AM
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

George2
February 18th, 2003, 07:53 PM
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