SmartPointer & Inheritance & Explicit Constructors

C

Chris Thomasson

[...]
This is simply not true in all cases. I can come up with several scaleable
memory management techniques that a traditional GC cannot compete with.
^^^^^^^^^^^^^^^^^^^^^^^

Some of the techniques can include special forms of reference counting.

[...]


I guess we should discuss some possible methods that can be used to reduce
the overhead in general-purpose garbage collectors. Any clever ideas?

;^)


Here are just a few of mine:

_____________________

http://groups.google.com/group/comp.lang.c++/browse_frm/thread/95007ffdf246d50e
(read whole thread...)


http://groups.google.com/group/comp.lang.c++.moderated/browse_frm/thread/65c9c2673682d4cf


http://appft1.uspto.gov/netacgi/nph...70".PGNR.&OS=DN/20070067770&RS=DN/20070067770
(a possible technique for a GC to use...)

_____________________


:^)
 
C

Chris Thomasson

Gianni Mariani said:
James Kanze wrote:
...

I have found that using smart pointers is almost all that is needed to
develop a leak free application.

Well, actually, nothing special is really "needed" to develop a leak-free
application... We all know that we can create leak-free programs by using
patience and discipline when designing their memory management techniques.

The circular pointers issue is normally very easy to design around.

Agreed.
 
C

Chris Thomasson

Bo Persson said:
Chris Thomasson wrote:
:: ::
:: [...] [...]

If the collector isn't run often (or at all, for typical benchmarks!), it
can be a net saving.

The collector can run quite often in certain scenarios... Its not really
something that can be predicted...
 
C

Chris Thomasson

C

Chris Thomasson

Jon Harrop said:
Symbolic expressions, any graph...

Seriously, if you're doing anything non-trivial, use a GC.

If you think you need a GC, then use a GC... The truth is that a GC is never
required for anything... Think about it? Can you give me an example of where
a GC is simply required to implement a particular algorithm?

GC is a convenience IMHO... If somebody thinks they "need" a GC to make
their programs correct, then perhaps programming is not one of their strong
points?
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

If you think you need a GC, then use a GC... The truth is that a GC is never
required for anything... Think about it? Can you give me an example of where
a GC is simply required to implement a particular algorithm?

GC is a convenience IMHO... If somebody thinks they "need" a GC to make
their programs correct, then perhaps programming is not one of their strong
points?

Or they've never learned to use anything else (like someone who started
with Java). The really interesting question (IMO) is whether one can
write all programs without using dynamically allocated memory except in
a few well understood and encapsulated places (like the standard
containers). Personally I seldom use dynamic memory/pointers in my
programs, so I don't really see what GC would give me.
 
C

Chris Thomasson

Erik Wikström said:
Or they've never learned to use anything else (like someone who started
with Java).

Good point.

The really interesting question (IMO) is whether one can write all
programs without using dynamically allocated memory except in a few well
understood and encapsulated places (like the standard containers).

I think disciplined use of dynamic allocation in the way you describe is
just evidence of a good overall design of your applications memory
management scheme(s)... IMHO at least...

;^)

Personally I seldom use dynamic memory/pointers in my programs, so I don't
really see what GC would give me.

I think GC would just add extra unwanted overhead to your programs... IMHO,
this is one of the reasons why GC should not be "forced" into the C++
Standard...
 
J

James Kanze

"James Kanze" <[email protected]> wrote in message
[...]
Garbage collection is not free, it can be somewhat expensive
in compute resources.
Which explains why programs using garbage collection are
typically faster than those without.
What type of garbage collection are you talking about?

The Boehm collector.
Some of the methods
used to actually implement most types of "general purpose" garbage
collection are overkill and can have an overall negative effect on
scalability and performance in general.

You can always find exceptions. I said generally.
IMHO, C++ simply does not need a GC.

Nor did it need templates, nor exceptions. It's just a tool
which means less work for the programmer.
 
J

James Kanze

Chris Thomasson wrote:

[...]
If the collector isn't run often (or at all, for typical benchmarks!),
it can be a net saving.

A benchmark in which the garbage collector never runs isn't very
convincing. It's easy, however, to construct special cases
where garbage collection is significantly faster than manual
memory management. Or significantly slower, if that's what
you're trying to prove. Never trust any benchmark you haven't
falsified yourself.

Globally, I find that for a large number of real applications,
using garbage collection results in slightly better performance.
Nothing to get excited about, but since it comes with
significantly less work for the programmer, it would be a shame
not to use it.

It would be just as wrong, however, to think that garbage
collection is a silver bullet, and that it will solve all of
your problems, or even that it is appropriate everywhere.
 
C

Chris Thomasson

Erik Wikström said:
On 2007-06-17 16:39, Chris Thomasson wrote: [...]
If GC does make it into the language, imho, it should be optional...

That seems to be a sentiment that the standards committee shares with you,
so never fear.


Good to here!
 
C

Chris Thomasson

Erik Wikström said:
On Jun 9, 10:16 am, Gianni Mariani <[email protected]> wrote:
[...]
IMHO, C++ simply does not need a GC.
Nor did it need templates, nor exceptions. It's just a tool
which means less work for the programmer.

If GC does make it into the language, imho, it should be optional...

That seems to be a sentiment that the standards committee shares with you,
so never fear.

Well, I think they have to keep the GC optional. If the force a low-level
systems language to use a GC, then it would not longer be all that
"practical" for __low-level__ operating system design...
 
J

James Kanze

"Erik Wikström" <[email protected]> wrote in message

[...]
Well, I think they have to keep the GC optional. If the force a low-level
systems language to use a GC, then it would not longer be all that
"practical" for __low-level__ operating system design...

I think that it's generally agreed that you should be able to
write a garbage collector in C++. Since you obviously can't use
garbage collection to implement the collector (without getting
endless recursion)...

But that's true for a lot of things already: std::vector can't
use std::vector in it's implementation, for example, but can
definitly be written in C++.

With regards to "optional": it depends on what you mean. There
is certainly no movement to force people to use garbage
collection where it isn't appropriate. On the other hand, I do
think that it should be required that a hosted implementation
support it---it's not optional for the implementation.
 
C

Chris Thomasson

"Erik Wikström" <[email protected]> wrote in message

[...]
I think that it's generally agreed that you should be able to
write a garbage collector in C++. Since you obviously can't use
garbage collection to implement the collector (without getting
endless recursion)...
Agreed.

[...]



With regards to "optional": it depends on what you mean. There
is certainly no movement to force people to use garbage
collection where it isn't appropriate.

Okay; that's definitely good news.


On the other hand, I do
think that it should be required that a hosted implementation
support it---it's not optional for the implementation.

Okay. I need a little clarification: Are you saying that any implementation
of the Standard C++ runtime for any architecture must have a full-blown
general-purpose garbage collector built-in it's infrastructure?
 
J

James Kanze

[...]
On the other hand, I do
think that it should be required that a hosted implementation
support it---it's not optional for the implementation.
Okay. I need a little clarification: Are you saying that any
implementation of the Standard C++ runtime for any
architecture must have a full-blown general-purpose garbage
collector built-in it's infrastructure?

I'm not sure concerning the latest evolution, but the last I
saw, a hosted implementation would not be conforming if it
wasn't possible to request the use of garbage collection. So
for hosted implementations, yes, although I'm not sure what you
mean by "built-in". It's a set of library components, plus
(probably) some compiler options. If you don't use it, you
shouldn't have to pay for it. (Except, of course, in that it
means that the library files will take up a little more space on
your disk, etc. The total cost will certainly be less than for
std::vector.)
 
C

Chris Thomasson

"Erik Wikström" <[email protected]> wrote in message
[...]
On the other hand, I do
think that it should be required that a hosted implementation
support it---it's not optional for the implementation.
Okay. I need a little clarification: Are you saying that any
implementation of the Standard C++ runtime for any
architecture must have a full-blown general-purpose garbage
collector built-in it's infrastructure?
I'm not sure concerning the latest evolution, but the last I
saw, a hosted implementation would not be conforming if it
wasn't possible to request the use of garbage collection. So
for hosted implementations, yes, although I'm not sure what you
mean by "built-in".

Built-in wrt garbage collector itself being hard-coded into some/all of the
libraries that make up the hosted implementations entire Standard C++
runtime...


It's a set of library components, plus
(probably) some compiler options. If you don't use it, you
shouldn't have to pay for it.

Indeed! ;^)


(Except, of course, in that it
means that the library files will take up a little more space on
your disk, etc. The total cost will certainly be less than for
std::vector.)

Okay. Well, I was just wondering if I would __have to__ create some sort of
"general-purpose" GC and incorporate it into the library(s) which make up
one of my custom C++ runtimes... Seems like your saying that I would have to
do "something" like that. I guess that's okay.

One other question... Would the GC have to be general-purpose? What would
the GC be required to protect? Does it have to track every single piece of
dynamically allocated memory? If I have to protect everything, then I don't
think I could apply some of the neat tricks I have learned over the years...
Well, I think that the GC Specification in the Standard should be "flexible"
enough to at least allow some PDR techniques to be used. For instance, I
think it could be beneficial if the Standard's wording could allow for
something like a "Proxy" Garbage Collector to be used instead of a
full-blown "Conventional" GC.

I am concerned that the GC rules wrt the std will rule out some novel
innovations in the areas of GC techniques/implementations and possible
usage-patterns...


Any thoughts?



___________________
P.S.
------- {
http://groups.google.com/group/comp.programming.threads/msg/41f29efe33e7f124
} (brief definition of Proxy GC...)


------- {
http://groups.google.com/group/comp.programming.threads/browse_frm/thread/b2f751d5dad6c07b
} (brief description of 'PDR')...
 
J

James Kanze

"James Kanze" <[email protected]> wrote in message
[...]
On the other hand, I do
think that it should be required that a hosted implementation
support it---it's not optional for the implementation.
Okay. I need a little clarification: Are you saying that any
implementation of the Standard C++ runtime for any
architecture must have a full-blown general-purpose garbage
collector built-in it's infrastructure?
I'm not sure concerning the latest evolution, but the last I
saw, a hosted implementation would not be conforming if it
wasn't possible to request the use of garbage collection. So
for hosted implementations, yes, although I'm not sure what you
mean by "built-in".
Built-in wrt garbage collector itself being hard-coded into some/all of the
libraries that make up the hosted implementations entire Standard C++
runtime...

It's still very much in a state of flux, but the last proposal I
saw provided for three cases: code which required garbage
collection, code which couldn't work with it, and code which was
garbage collection neutral. Presumably, the standard libraries,
and most third party libraries, would be designed to fall into
the last category. (Although I suspect that more than a few
implementations would offer two sets of libraries, one of which
required garbage collection, simply because something like
std::basic_string can be made a lot faster if you can count on
garbage collection being present.)

[...]
Okay. Well, I was just wondering if I would __have to__ create some sort of
"general-purpose" GC and incorporate it into the library(s) which make up
one of my custom C++ runtimes... Seems like your saying that I would have to
do "something" like that. I guess that's okay.

I'm not sure what you mean here. The obvious goal would be to
make most existing C++ code garbage collection neutral; to
define the requirements such that most existing code met them.
Third party libraries, except in special cases where they do
something funny, will probably automatically be garbage
collection neutral.
From what little I understand of your work, you'll be much more
affected by the threading definitions which are added to the
standard.
One other question... Would the GC have to be general-purpose? What would
the GC be required to protect? Does it have to track every single piece of
dynamically allocated memory? If I have to protect everything, then I don't
think I could apply some of the neat tricks I have learned over the years....
Well, I think that the GC Specification in the Standard should be "flexible"
enough to at least allow some PDR techniques to be used. For instance, I
think it could be beneficial if the Standard's wording could allow for
something like a "Proxy" Garbage Collector to be used instead of a
full-blown "Conventional" GC.
I am concerned that the GC rules wrt the std will rule out some novel
innovations in the areas of GC techniques/implementations and possible
usage-patterns...
Any thoughts?

The obvious intent is not too. The general philosophy of C++ is
to rule out as little as possible (and it's a philosophy which
has paid off in the long run). The issue is still under active
discussion, however, and it's hard to say exactly what the final
form will be.
 
J

Jerry Coffin

[ ... ]
It's still very much in a state of flux, but the last proposal I
saw provided for three cases: code which required garbage
collection, code which couldn't work with it, and code which was
garbage collection neutral. Presumably, the standard libraries,
and most third party libraries, would be designed to fall into
the last category. (Although I suspect that more than a few
implementations would offer two sets of libraries, one of which
required garbage collection, simply because something like
std::basic_string can be made a lot faster if you can count on
garbage collection being present.)

The most recent draft I've looked at on it is N2287. It fairly
specifically does NOT say you can ever depend on GC being present. The
closest it comes is a note that says [basic.stc.collect]:

[ Note: For garbage collected programs, a high quality
hosted implementation should attempt to maximize the
amount of unreachable memory it reclaims. ?end note ]

That's it. There's a lot of language to define things like what
constitutes unreachable memory. When you get down to it, however, a
large part of the idea is that the garbage collection is transparent --
which means it has no externally visible effect on the program.

I know a lot of people really want garbage collection, and I know some
smart people have really put some hard work into it -- but when you get
down to it, trying to specify GC in terms of externally visible,
required behavior is nearly impossible. There's no guarantee that any
allocation will ever succeed, and basically all GC can ever do do is
increase the chance of an allocation succeeding.

Other than that, N2287 adds some mechanisms that attempt to give you
control over whether GC is optional, required, etc. -- but with no clear
definition of what GC really does (and probably none possible) it's
pretty easy for an implementation to "conform" by saying GC is present,
but never providing a real implementation (i.e. GC is simply a NOP).

There are, of course a few real rules to be added -- basically just a
restriction against pointer swizzling, and other such things that
prevent a pointer from being recognized (well, it's not really a
restriction against it -- but the code has undefined behavior if it
attempts to dereference a pointer after it's been unrecognizable for any
period of time).

[ ... ]
The obvious intent is not too. The general philosophy of C++ is
to rule out as little as possible (and it's a philosophy which
has paid off in the long run). The issue is still under active
discussion, however, and it's hard to say exactly what the final
form will be.

At least based on the papers I've looked at so far, very little will be
ruled out in terms of implementation. At least in my view, the problem
is much more that code will be restricted without guaranteeing anything
in return. The only comfort is that the restrictions are pretty trivial.
 
C

Chris Thomasson

[...]
It's still very much in a state of flux, but the last proposal I
saw provided for three cases: code which required garbage
collection, code which couldn't work with it, and code which was
garbage collection neutral.
[...]

The most recent draft I've looked at on it is N2287. It fairly
specifically does NOT say you can ever depend on GC being present. The
closest it comes is a note that says [basic.stc.collect]:
[ Note: For garbage collected programs, a high quality
hosted implementation should attempt to maximize the
amount of unreachable memory it reclaims. ?end note ]
That's it.

Sound pretty good...

There's a lot of language to define things like what
constitutes unreachable memory.

That's the kind of broad statements I think we need when defining GC, or a
memory model for that matter, in the standard.
[...]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,195
Latest member
tewan

Latest Threads

Top