K
Kenny McCormack
heathfield FORBID ME EXPLICIRELY to call him by his first
name. Before I called him "richard" but HE told me not to do so.
Then I suppose calling him [a] Dick would be right out, as well.
heathfield FORBID ME EXPLICIRELY to call him by his first
name. Before I called him "richard" but HE told me not to do so.
Ben said:jacob navia said:[garbage collection]
I'd suggest use of resource pools as a viable alternative to
garbage collection that can actually be implemented in standard
C. Resource pools are not perfect, but when used in a
disciplined way they can make some kinds of programming much
simpler.
Here's a discussion of what I mean:
http://freetype.sourceforge.net/david/reliable-c.html
jacob said:Well, this is NON-STANDARD. As far as C is concerned, a subtractingFlash said:jacob said:William Hughes wrote:
jacob navia wrote:
[...]
This is of no practical significance. Pointers aren't XORed in normal
programs, and if you stay within the normal alignment requirements
of the processor, everything works without any problems.
No, but I might well subtract 1 from my pointers to change the
indexing.
This is allowed of course. Your pointer will be within the bounds
of the pointed-to object and that object will NOT be reclaimed since
there is (at least) one pointer to somewhere in it.
You missed William's point entirely.
p = malloc(N * sizeof *p) -1; /* I now have an array indexed by 1 */
Non-standard, but people do it. It means that the pointer is no longer
no longer points in to the object, so the GC will free it.
one from the start of an object is undefined behavior.
If you do things like that yes, you should not use the GC.
You can
however have the same effect by
p = malloc((1+N) * sizeof *p) ; /* I now have an array indexed by 1 */
You never use the zeroth member and you keep out of undefined behavior.
Exvuse me but that is likely to be done by the OS, not by a third party
library.
Maybe, I can't guarantee all third party libraries in the world. As far
as I know, and from the experience of people using the GC, that never
happens.
William said:So. Are you claiming that GC will work on any conforming program?
In any case, by casting from a pointer to an integer, subtracting
the size of an array element, and casting back to a pointer, I get
implementation defined behaviour, which will probably be the
behaviour I want.
And this is my point. If you do things like that you shouldn't use
GC. It took me 30 seconds to come up with that example. This
does not give me a warm fuzzy about GC.
The fact that you can do things that don't break GC is not the
point. The fact that you can do things that do break GC and that
these things are not that unlikely , is.
So? The program may have a better idea of what is going
to be needed next than the OS. In that case the program may well
implement its own "swapping" mechanism. This is certainly not
likely, but it is not that rare either.
I have used a lot of NR code. Good thing I never used
GC.
So. Are you claiming that GC will work on any conforming program?
jacob said:As I said, that is undefined behavior in C.
It happens to work in YOUR implementation, it will not work in a
segmented implementation where pointer arithmetic is not defined
at a segment boundaries, for example any 286 compatible processor.
Well, if you do things that are not allowed by the standard
you are in your own.
It is funny the contortions people will invent to find something that
is against a GC.
We both agree that "this is certainly not likely".
NR code invokes undefined behavior if it subtracts one from
the beginning of the array. I repeat. That works in some
implementations, in some others it will break.
I think this particular carp is unfair. Jacob has been
fundamentally advertising the available of the Boehm library for
GC, which I presume is written in standard C, or nearly so.
Frederick said:William Hughes posted:
It's simple to write a fully-portable GC.
The question is whether it will
work on any conforming program.
This includes a program that allocates some memory,
xor's a pointer twice with the same string, and
then uses the memory.
Which wasn't the question.
It doesn't matter if the GC is written in a combination of
assembler and Lithp ( a programming language that the Igors
use to process lithtths). The question is whether it will
work on any conforming program.
This includes a program that allocates some memory,
xor's a pointer twice with the same string, and
then uses the memory.
Frederick Gotham said:Even something as primitive as the following should work
As I think you must know, that's not garbage collection in the sense
being discussed.
Frederick said:William Hughes posted:
Why do think it might not work? I don't see any barriers.
Default User said:jacob navia wrote:[inflammatory off-topic crap]
Ok, that's finally enough for a plonk.
Walter said:In order to xor a pointer with anything, you would need to
convert the pointer into an integral value, then convert the
integral value to a pointer and have the resulting pointer compare
equal to the original pointer.
C89 and C99 allow implementations to define casting pointers to and
from integral values, but does not define the meaning of that
conversion. C99 promises that the conversion is reversable, but C89
does not (but K&R2 does.)
jacob said:Why should the destructors be touched? They just
do not call free() (delete in C++) and that is it.
Al said:That doesn't make it topical. He's discussing the product, not the
code. As we keep reminding people here, the fact that a program is
written in C doesn't make discussion of the program itself topical.
[...]In order to xor a pointer with anything, you would need to
convert the pointer into an integral value, then convert the
integral value to a pointer and have the resulting pointer compare
equal to the original pointer.
Bart said:<OT>
Code that relies on objects being destroyed at a specific point is very
common in C++ (e.g. the standard C++ library). GCs don't guarantee
*when* objects are deallocated, only that they do eventually get
deallocated. BTW, that's the reason Java has a 'finally' clause instead
of destructors.
</OT>
Regards,
Bart.
jacob said:You misunderstand. The object *IS* destroyed. Only its storage is
not reclaimed. The destructor is called as the C++ rules want. It just
doesn't call delete.
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.