home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!psinntp!wrldlnk!usenet
- From: "John F. Isner" <wk01696@worldlink.com>
- Subject: Re: USL C++ Standard Components - A bug?
- In-Reply-To: <1992Dec13.195120.4368@tagsys.com>
- Message-ID: <2934249994.1.wk01696@worldlink.com>
- Sender: usenet@worldlink.com
- Nntp-Posting-Host: 127.0.0.1
- Organization: Nomura Research Institute
- Date: Thu, 24 Dec 1992 03:00:50 GMT
- X-Mailer: WORLDLink (3.11)
- Lines: 60
-
- >DATE: Sun, 13 Dec 1992 19:51:20 GMT
- >FROM: Andrew Gideon <andrew@tagsys.com>
- >
- >I have just started working with the USL/C++ Standard
- >Components for a new client. Already, I may have found
- >a very serious problem. I hope that I'm wrong.
- >
- >I have been working with the Rogue Wave tools.h++ product for
- >quite a while. One of the first things that I did was
- >construct deep collections from the RW shallow collections.
- >It was nice to see that USL had already thought of this
- >(USL calls deep collections "object collections" and shallow
- >collections "pointer collections" - some people still publish
- >implementation {8^).
- >
- >But in my first set of experiments, I immediately noticed
- >that something was wrong with the deep sets in USL.
- >
- >When insert()ing objects into a deep set, the copy
- >constructor is used to create new instances. The object
- >passed in the insert() method is still owned by the caller
- >of insert() - the new copy is held by the set.
- >
- >But when a deep set is destructed, the contained objects are
- >NOT destructed. Further, objects that are remove()ed are also
- >not destructed.
- >
- >I could find no way (w/o unsafe casts) to get around this.
- >(And even with unsafe casts, I doubt that it would work)
- >
- >This seems like a memory leak. Am I missing something?
- >Help, please?
- >
- > Andrew Gideon
-
- USL Sets and Set_of_p's (pointer sets) are quite different,
- not only in implementation, but in semantics. A Set_of_p
- is implemented using a data structure optimized to support
- set operations on void*'s. The generic wrapper around this
- data structure it is merely for type safety, and generates
- no code. The elements of a Set_of_p are T*'s. Memory
- management for the T's pointed to by the Set_of_p is the
- responsibility of the client. This is stated quite clearly
- USL's documentation.
-
- USL's Sets and Bags, on the other hand, are containers for
- objects. As you correctly state, objects inserted into them
- are copied using T(const T&). However the copies ARE fully
- managed by the container. For example, the implementation
- uses a hashing scheme with collision lists; removing an
- object from a Set is implemented by finding and deleting
- the list node containing the object. when the node is deleted,
- ~T() is invoked. Destroying the Set destroys all the lists,
- hence all the nodes, hence all the objects they contain.
-
- I have been using the USL Standard Components for several
- years, both inside AT&T and in my current job. To the best
- of my knowedge, they are free of memory leaks.
-
- John Isner
-