"Alex Vinokur" <al****@big-foot.com> wrote in message news:2n************@uni-berlin.de...
"Sharad Kala" <no******************@yahoo.com> wrote in message news:2n************@uni-berlin.de...
"Alex Vinokur" <al****@big-foot.com> wrote in message
news:2n************@uni-berlin.de...
When should 'construct' and 'destroy' be invoked?
An allocator has to provide a construct and destruct operation. You may want
to take a look at 20.1.5 (Allocator requirements).
Construct is used to initialize the memory allocated with a value. This is
basically a call to placement new. So basically construct is invoked when an
object is created in the container.
For instance, v.push_back (element) for vector?
However, in http://www.josuttis.com/libbook/memo...lloc1.cpp.html construct isn't invoked while push_back invocation.
Destroy simply calls the destructor for the object.
-Sharad
[snip]
Compiler g++ 3.3.1 (cygming special).
Here is a fragment from file stl_alloc.h.
/**
* @defgroup Allocators Memory Allocators
* @if maint
* stl_alloc.h implements some node allocators. These are NOT the same as
* allocators in the C++ standard, nor in the original H-P STL. They do not
* encapsulate different pointer types; we assume that there is only one
* pointer type. The C++ standard allocators are intended to allocate
* individual objects, not pools or arenas.
*
* In this file allocators are of two different styles: "standard" and
* "SGI" (quotes included). "Standard" allocators conform to 20.4. "SGI"
* allocators differ in AT LEAST the following ways (add to this list as you
* discover them):
*
* - "Standard" allocate() takes two parameters (n_count,hint=0) but "SGI"
* allocate() takes one paramter (n_size).
* - Likewise, "standard" deallocate()'s argument is a count, but in "SGI"
* is a byte size.
* - max_size(), construct(), and destroy() are missing in "SGI" allocators.
* - reallocate(p,oldsz,newsz) is added in "SGI", and behaves as
* if p=realloc(p,newsz).
*
* "SGI" allocators may be wrapped in __allocator to convert the interface
* into a "standard" one.
* @endif
*
* @note The @c reallocate member functions have been deprecated for 3.2
* and will be removed in 3.4. You must define @c _GLIBCPP_DEPRECATED
* to make this visible in 3.2; see c++config.h.
*
* The canonical description of these classes is in docs/html/ext/howto.html
* or online at
http://gcc.gnu.org/onlinedocs/libstd...t/howto.html#3
*/
Perhaps, MyAlloc in the Josuttis' sample works as "SGI" allocator which doesn't contain construct(), and destroy() (?).
--
Alex Vinokur
http://mathforum.org/library/view/10978.html http://sourceforge.net/users/alexvn