Topic: Q regarding implementation of dynarray


Author: howlett@netcom.com (J. Scott Howlett)
Date: Tue, 7 Feb 1995 02:39:05 GMT
Raw View
I recently purchased "The Draft Standard C++ Library". In the section
covering the dynarray template class, I noticed that the array is built
with a statement like "new T[n];" It seems that this is unnecessary. It
requires you to make an excessive constructor calls. Also, removing an
element of the array does not seem to always actually cause that element
to be destroyed. This seems very bad.

This seems to be a case where differing implementations would cause the
array class to behave differently. For example, the implementation in the
book would seem to not allow this:

typedef thing_I_can_only_have_10_of foo;

foo f; // Makes one foo
dynarray<foo> arr(f,5); // Makes 5 more
arr.remove(1,4); // Remove (not really!!!!) 4 of them
dynarray<foo> arr2(f,5); // Should be a total of 7 now, but really 11!

Couldn't this stuff be handled better with explicit in-place construction
and destruction of elements of type T in an array which was allocated and
deallocated using the form (T *)new char[n * sizeof(T)]; Or am I missing
something important?

Thanks for any light anyone may shed on this subject.

--
Scott Howlett
Storm Software, Inc.
howlett@netcom.com




Author: jason@cygnus.com (Jason Merrill)
Date: Tue, 7 Feb 1995 12:25:30 GMT
Raw View
dynarray is no longer part of the C++ Standard Library, having been
superceded by STL vectors.

Jason