10 Jan, 2009, Lobotomy wrote in the 1st comment:
Votes: 0
Self-explanatory topic. :thinking:
11 Jan, 2009, ghasatta wrote in the 2nd comment:
Votes: 0
Not really. What do you mean by best? Have you looked at the boehm-demers-weiser gc? http://www.hpl.hp.com/personal/Hans_Boeh...
11 Jan, 2009, Lobotomy wrote in the 3rd comment:
Votes: 0
Best. I was intentionally vague so as to get what would hopefully be a swath of various sources, opinions, etc, on the matter. I have seen the Boehm-etc garbage collector, however so far it's the only one I've found/heard of. I would hope that it's not the only C garbage collector that exists. In the case that it isn't, I'm looking to hear about which one is the best among them. However, if it is the only one that there is then that'll pretty much answer my question. :thinking:
11 Jan, 2009, David Haley wrote in the 4th comment:
Votes: 0
Why C and not C++? Why do you care? I postulate that you shouldn't. If you want to use no C++ features, that's fine, but I see no need to limit your search. And I'm assuming you've tried googling this? There are very many out there. I don't know them off-hand because I don't believe in GC in C/C++ – personally I think that this is kind of comparable to trying to retrofit a screwdriver head onto a hammer. Use a language with GC if you want GC, use C/C++ for what they're good for if that's what you need.

And it really does help to specify what you mean by "best" – you could mean any number of things, from ease of use, to efficiency, to absolute correctness (e.g. can it handle cyclical unreachable structures). That will help people give better answers based on what exactly you're trying to do here.
11 Jan, 2009, Lobotomy wrote in the 5th comment:
Votes: 0
DavidHaley said:
Why C and not C++? Why do you care? I postulate that you shouldn't. If you want to use no C++ features, that's fine, but I see no need to limit your search.

As previously stated, I use C99 which conflicts with current-day C++. Now, I'm not particularly knowledgable about the differences of C99 and C++ (although I probably should be), but for the sake of example I looked up one such feature missing from C++: variable length arrays. For instance, in C++ you can't do the following (yet):

void example( int length )
{
int test[length];
}

…whereas in C99, you can. There's more differences, however this is not the thread I want to be discussing them in. I started a different thread explicitly for that purpose.

DavidHaley said:
Use a language with GC if you want GC, use C/C++ for what they're good for if that's what you need.

Sir, yes, sir!

DavidHaley said:
And it really does help to specify what you mean by "best" – you could mean any number of things, from ease of use, to efficiency, to absolute correctness (e.g. can it handle cyclical unreachable structures). That will help people give better answers based on what exactly you're trying to do here.

I am looking for an overall best, as (should be) implied by the use of "best" in general.
11 Jan, 2009, Tyche wrote in the 6th comment:
Votes: 0
11 Jan, 2009, David Haley wrote in the 7th comment:
Votes: 0
Lobotomy said:
DavidHaley said:
Use a language with GC if you want GC, use C/C++ for what they're good for if that's what you need.

Sir, yes, sir!

Mocking people who reply to this kind of thread is probably not the best way to get responses to this kind of thread in the future. If you disagree with my statement, that's fine and we can talk about that, but the above isn't terribly constructive.

Lobotomy said:
I am looking for an overall best, as (should be) implied by the use of "best" in general.

There is generally no such thing as an "overall best", especially when discussing something so complex. It's kind of like asking what the "overall best" programming language is. At this point, your question is so open that doing some poking around of your own might be the most helpful (Tyche provided you the links that a Google search would). I suspect that not many people use garbage collection in C, for the reason I gave earlier (that you apparently did not like very much).
11 Jan, 2009, The_Fury wrote in the 8th comment:
Votes: 0
DavidHaley said:
Lobotomy said:
DavidHaley said:
Use a language with GC if you want GC, use C/C++ for what they're good for if that's what you need.

Sir, yes, sir!

Mocking people who reply to this kind of thread is probably not the best way to get responses to this kind of thread in the future. If you disagree with my statement, that's fine and we can talk about that, but the above isn't terribly constructive.


You cannot blame the guy really for showing his frustration, he did as a specific question that Tyche has managed to answer, where as every other reply has been more or less an opinion about the pro's and con's of doing what Lobotomy wants to do.

Lobotomy is not some brainless noob with no idea about what he is doing, so i think its save to assume that he has thought through his actions, understands the ramifications of them, knows that there maybe better language solutions and a more direct reply to actual experiences in using the tools he is looking at might actually help him more.

@Lobotomy, sorry but i have no idea about the things your doing so i can be of no assistance, other than that since i have started to use a language with garbage collection i can understand why you would want to include such in a C project. These things make live so easy and i don't know how i ever lived without such niceties. I wish you luck.
11 Jan, 2009, Lobotomy wrote in the 9th comment:
Votes: 0
Tyche said:
Garbage collectors (assume free and C++ can of course be backported to C)
GC: A garbage collector for C and C++
SGC: A Parallel Conservative Garbage Collector on Shared-Memory Multiprocessors
A Generational Garbage Collector in C++
HnxGC - an accurate, pauseless & deterministic garbage collector
Conservative Garbage Collector for C
Smieciuch Garbage Collector

There are also muds that use reference counting garbage collectors…
CoolMud

Thanks. :smile:

DavidHaley said:
Mocking people who reply to this kind of thread is probably not the best way to get responses to this kind of thread in the future. If you disagree with my statement, that's fine and we can talk about that, but the above isn't terribly constructive.

If you want to persuade me towards using C++ or some other language for whatever reason, I have no problem whatsoever in hearing discussion on that matter (although not in this thread, of course). The problem is that you phrased your comment in the form of an order, something I don't myself find terribly constructive nor appreciate in the slightest; hence the jab I made in reply to it.

The_Fury said:
Lobotomy is not some brainless noob with no idea about what he is doing, so i think its save to assume that he has thought through his actions, understands the ramifications of them, knows that there maybe better language solutions and a more direct reply to actual experiences in using the tools he is looking at might actually help him more.

You've hit the nail on the head.

The_Fury said:
@Lobotomy, sorry but i have no idea about the things your doing so i can be of no assistance, other than that since i have started to use a language with garbage collection i can understand why you would want to include such in a C project. These things make live so easy and i don't know how i ever lived without such niceties. I wish you luck.

Out of curiosity, which language is it that you mention you've started using?
12 Jan, 2009, The_Fury wrote in the 10th comment:
Votes: 0
Quote
Out of curiosity, which language is it that you mention you've started using?


If i tell you, i would have to kill you. :) Seriously tho, i have been using Ruby. The speed at which you can get things working is amazing. As for what i have been doing with it, you will have to wait till I make an announcement. :)
12 Jan, 2009, David Haley wrote in the 11th comment:
Votes: 0
Lobotomy said:
If you want to persuade me towards using C++ or some other language for whatever reason, I have no problem whatsoever in hearing discussion on that matter (although not in this thread, of course). The problem is that you phrased your comment in the form of an order, something I don't myself find terribly constructive nor appreciate in the slightest; hence the jab I made in reply to it.

If you truly thought I was giving an order, I'm not really sure what to say other than that was a considerable misinterpretation. I didn't realize that not prefacing everything I write with "IMHO you might want to possibly consider" would make things into orders. :wink: Seriously: the phrase that you found so objectionable was meant as nothing more than the conclusion of the previous sentences…

Anyhow, I think it's pretty clear that I think you're doing something you shouldn't be doing, and are trying to retrofit things onto C/C++ that they're just not really meant for – and that you'd be much better off doing something else. If you don't want to hear about that now, that's fine with me; I think I've made my point sufficiently for the purposes of the current discussion.
12 Jan, 2009, Tyche wrote in the 12th comment:
Votes: 0
A followup to the earlier thread, String utility functions - Storage metho... started by Lobotomy.
This one using variable arrays allocated on the stack like C99 and the Boehm-Demers-Weiser conservative garbage collector.

#include <stdio.h>
#include <alloca.h>
#include <ctype.h>

// method 7 - like method 3
// return new string
//
// reentrant, caller must free string
// alloca() is equivalent to C99 variable arrays and while not
// necessarily portable more portable than C99 at this point.
char * capitalize_7(char const* src) {
char * dst = (char *) alloca(strlen(src) + 1);

strcpy(dst, src);
if (strlen(dst) > 0)
*dst = toupper(*src);
return strdup(dst);
}

#include "gc.h"
// method 8 - like method 3
// return new garbage collected string
//
// reentrant, caller need NOT free string
char * capitalize_8(char const* src) {
char * dst = GC_MALLOC_ATOMIC(strlen(src) + 1);

strcpy(dst, src);
if (strlen(dst) > 0)
*dst = toupper(*src);
return dst;
}

int main() {
char a[6] = "hello";
char * sptr;

sptr = capitalize_7(a);
printf("7: %s %s\n",a, sptr);
free(sptr);

sptr = capitalize_8(a);
printf("8: %s %s\n",a, sptr);

return 0;
}




$ gcc capitalize3.c -lgc; ./a
7: hello Hello
8: hello Hello
12 Jan, 2009, Tyche wrote in the 13th comment:
Votes: 0
Also for those more curious about variable arrays but don't have a compiler that supports it yet.
It doesn't have to be real ugly.

#include <stdio.h>
#include <alloca.h>

#define VAR_ARRAY(X,Y,Z) X * Y = (X *) alloca(Z * sizeof(X))

// pre C99 variable arrays
// return copy of string
//
char * copy(char const* src, int len) {
VAR_ARRAY(char, dst, len);

strcpy(dst, src);
return strdup(dst);
}

// pre C99 variable arrays
// allocate an integer array and print it
//
void fill_n_print_array(int len) {
int i;
VAR_ARRAY(int, b, len);

for (i=0; i<len; i++)
b[i] = i;

for (i=0; i<len; i++)
printf("%d ", b[i]);
printf("\n");
}

int main() {
char a[6] = "hello";

char * sptr = copy(a, strlen(a)+1);
printf("copy: %s %s\n",a, sptr);
free(sptr);

fill_n_print_array(5);
fill_n_print_array(20);

return 0;
}
12 Jan, 2009, Lobotomy wrote in the 14th comment:
Votes: 0
DavidHaley said:
If you truly thought I was giving an order, I'm not really sure what to say other than that was a considerable misinterpretation. I didn't realize that not prefacing everything I write with "IMHO you might want to possibly consider" would make things into orders. :wink: Seriously: the phrase that you found so objectionable was meant as nothing more than the conclusion of the previous sentences…

Anyhow, I think it's pretty clear that I think you're doing something you shouldn't be doing, and are trying to retrofit things onto C/C++ that they're just not really meant for – and that you'd be much better off doing something else. If you don't want to hear about that now, that's fine with me; I think I've made my point sufficiently for the purposes of the current discussion.

In retrospect, I must say that I misspoke earlier (it's not particularly graceful to misunderstand myself in addition to others, but…meh); it was not the form of the comment that I originally took issue with, but the substance. Regardless of that, though, I'd like to offer you my apologies for my comment(s) and just move on. I'm starting to think that you may very well be right, in that so long as I remain using a language like C/C++ which lacks a built-in garbage collector that I should just stick with manual memory management.
15 Jan, 2009, David Haley wrote in the 15th comment:
Votes: 0
No worries at all! :smile: The reason I made the comment FWIW is that I've tried similar things in C++ myself, and found that it just wasn't really working. I kept feeling like I was trying to write Java but in C++, and I wasn't seeing the point of that.
0.0/15