|
-
February 14th, 2003, 07:06 AM
#1
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
-
February 15th, 2003, 02:12 AM
#2
-
February 18th, 2003, 06:03 AM
#3
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
-
February 18th, 2003, 08:53 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|