D - Template Library
- Craig Black (7/7) Mar 29 2004 If I recall correctly, D has had templates for a number of months now. ...
- Brad Anderson (4/15) Mar 29 2004 Search the NG for DTL - Matthew Wilson is running his lib by Walter
- Stewart Gordon (11/18) Mar 30 2004 How would this be an improvement over D's built-in dynamic arrays?
- Craig Black (10/20) Apr 01 2004 D arrays optimized for adding single elements as std::vector is?
- Ilya Minkov (9/14) Apr 01 2004 I recall there were plans to mark "ownership" of an array with a bit
- J Anderson (5/15) Apr 01 2004 I think it will probably be Mathews DTL.
- Stewart Gordon (24/32) Apr 01 2004 Yes, implementation permitting.
- J Anderson (8/15) Apr 01 2004 Walter did mention something about the GC allocating double the required...
- Craig Black (10/15) Apr 01 2004 I don't believe that std::vector just doubles the size. If you observe ...
- J Anderson (13/23) Apr 02 2004 BTW: I can't remember exactly what big W said so take that with a grain
-
Stewart Gordon
(11/19)
Apr 02 2004
If I recall correctly, D has had templates for a number of months now. Are D templates usable yet? Is there standard container/collection library for D like the Standard Template Library for C++? If so, what is currently available? I'm looking for things like linked-lists, autosizing arrays like std::vector, binary-tree-based containers like std::set, and hash tables. Thanks, Craig
Mar 29 2004
Craig Black wrote:If I recall correctly, D has had templates for a number of months now. Are D templates usable yet? Is there standard container/collection library for D like the Standard Template Library for C++? If so, what is currently available? I'm looking for things like linked-lists, autosizing arrays like std::vector, binary-tree-based containers like std::set, and hash tables. Thanks, CraigSearch the NG for DTL - Matthew Wilson is running his lib by Walter right now. Should see it soon. BA
Mar 29 2004
Craig Black wrote:If I recall correctly, D has had templates for a number of months now. Are D templates usable yet?Yes. I've used them, for instance.Is there standard container/collection library for D like the Standard Template Library for C++? If so, what is currently available? I'm looking for things like linked-lists, autosizing arrays like std::vector,How would this be an improvement over D's built-in dynamic arrays?binary-tree-based containers like std::set, and hash tables.Any particular improvements you're looking for over D's built-in associative arrays? But do see (if you haven't already) my version at http://smjg.port5.com/pr/d/ Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
Mar 30 2004
D arrays optimized for adding single elements as std::vector is? std::vector is optimized so that it doesn't have to resize every time you add a single element. The last time I researched this a few months ago D arrays did not have this property. Perhaps the situation has changed. It's a really nice feature.Is there standard container/collection library for D like the Standard Template Library for C++? If so, what is currently available? I'm looking for things like linked-lists, autosizing arrays like std::vector,How would this be an improvement over D's built-in dynamic arrays?Correct me if I'm wrong. Last I heard, D associative arrays work only with char[] type, so they lack the flexibility provided by a generic class.binary-tree-based containers like std::set, and hash tables.Any particular improvements you're looking for over D's built-in associative arrays?But do see (if you haven't already) my version at http://smjg.port5.com/pr/d/Cool! Keep up the good work, Stewart! Perhaps Walter will add an official template library to D so that we can all contribute to a common library. Craig
Apr 01 2004
Craig Black schrieb:D arrays optimized for adding single elements as std::vector is? std::vector is optimized so that it doesn't have to resize every time you add a single element. The last time I researched this a few months ago D arrays did not have this property. Perhaps the situation has changed. It's a really nice feature.I recall there were plans to mark "ownership" of an array with a bit within the length field. Something like a simple reference counting. And if there is only one owner, the array can be resized using realloc, and is preallocated with power-of-2 size, IIRC. Burton was planning to make it in his experimental compiler, but he didn't. I don't know whether DMD has this feature or has it been considered at all. But for the future, it is an option. -eye
Apr 01 2004
Craig Black wrote:Correct me if I'm wrong. Last I heard, D associative arrays work only with char[] type, so they lack the flexibility provided by a generic class.This is wrong. D's associative arrays can be used with class objects.I think it will probably be Mathews DTL. -- -Anderson: http://badmama.com.au/~anderson/But do see (if you haven't already) my version at http://smjg.port5.com/pr/d/Cool! Keep up the good work, Stewart! Perhaps Walter will add an official template library to D so that we can all contribute to a common library. Craig
Apr 01 2004
Craig Black wrote: <snip>Yes, implementation permitting.How would this be an improvement over D's built-in dynamic arrays?D arrays optimized for adding single elements as std::vector is?std::vector is optimized so that it doesn't have to resize every time you add a single element. The last time I researched this a few months ago D arrays did not have this property.I don't think D arrays have any implementation specifics set in stone. Besides (possibly) the elements being contiguous in memory. In which case, it's perfectly valid for an implementation to set aside some growing space. IRHS you can already create some growing space yourself (again, this would be implementation dependent): int[] qwert; qwert.length = 100; qwert.length = 0; <snip>Correct me if I'm wrong. Last I heard, D associative arrays work only with char[] type, so they lack the flexibility provided by a generic class.<snip> I've had no problem using it with an integer type. This is indeed how my hash map template is implemented. Besides, if D associative arrays were only supposed to work with char[], chances are the declaration syntax would have omitted the key type altogether. Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
Apr 01 2004
Stewart Gordon wrote:Walter did mention something about the GC allocating double the required memory. There may be some good reasons for an vector class that allows you to provide your own allocator. Personally I'd have little use for such a thing (I always use the default allocator in C++). -- -Anderson: http://badmama.com.au/~anderson/add a single element. The last time I researched this a few months ago D arrays did not have this property.std::vector is optimized so that it doesn't have to resize every time you I don't think D arrays have any implementation specifics set in stone. Besides (possibly) the elements being contiguous in memory. In which case, it's perfectly valid for an implementation to set aside some growing space.
Apr 01 2004
Walter did mention something about the GC allocating double the required memory.I don't believe that std::vector just doubles the size. If you observe the growth rate of std::vector as you add elements, it increases each time by a certain percentage, say 30% or so. Personally this more conservative approach is more attractive to me. It wastes less memory and still maintains decent performance.There may be some good reasons for an vector class that allows you to provide your own allocator. Personally I'd have little use for such a thing (I always use the default allocator in C++).Yeah, me neither. I'm sure the customizable allocator feature was useful for somebody, but I never got into it. Too much work, requires a lot of research to find out the best allocation algorithm. Better if someone else does this for me. Craig
Apr 01 2004
Craig Black wrote:BTW: I can't remember exactly what big W said so take that with a grain of salt. There's also a capacity thing in gcx.d that get's the capacity of a pointer but I don't think this is accessible.Walter did mention something about the GC allocating double the required memory.I don't believe that std::vector just doubles the size. If you observe the growth rate of std::vector as you add elements, it increases each time by a certain percentage, say 30% or so. Personally this more conservative approach is more attractive to me. It wastes less memory and still maintains decent performance.Maybe but I think it depends on the application. If you know your application though you can almost always write a better scheme manually. I don't think D should do this directly (D needs to keep to the metal). I think it should be done as part of the library (as you've suggested). But it seems more like a boost thing then an std thing. I guess the lib would come with a range of pre-defined allocators that can be plugged in. -- -Anderson: http://badmama.com.au/~anderson/
Apr 02 2004
J Anderson wrote:Stewart Gordon wrote:<snip><snip> Can it reduce this factor if there isn't enough spare memory to double the capacity? Further, can a GC pass reduce the growing capacity of an already allocated array? Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.I don't think D arrays have any implementation specifics set in stone. Besides (possibly) the elements being contiguous in memory. In which case, it's perfectly valid for an implementation to set aside some growing space.Walter did mention something about the GC allocating double the required memory.
Apr 02 2004