Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Teach me to remove bloat!

Name: Anonymous 2010-02-24 0:34

Hey guys, I would like some pointer (no, not that kind) on removing bloat in code. Here is a fully functional piece of code that I wrote which I'm worried about bloat in. How do I shorten this?

int get_input()
{
    int count, paren_count, total_count, c;
    char *input, *temp;

    input = (char *) malloc (500 * sizeof (char));

    if (input == NULL) return 0;
    printf("%% ");
    for (count = paren_count = total_count = 0; (c = getchar()) != EOF; count++, input++, total_count++)
    {
        if (count == 499)
        {
            input -= total_count;
            temp = (char *) realloc (input, (500 + total_count) * sizeof (char));
            if (temp == NULL)
                return 0;
            input = temp;
            input += total_count;
        }
        if (c == '\n')
        {
            *input = '\0';
            temp = input;
            temp -= (count);
            count = 0;
            for (; *temp != '\0'; temp++)
            {
                if (*temp == '(')
                    paren_count++;
                else if (*temp == ')')
                    paren_count--;
            }
            if (paren_count == 0)
                break;
            printf("  ");
        }
        *input = c;
    }
    *temp = '\0';
    input -= total_count;
    printf("%s\n", input);
    free(input);
    return 0;
}

Name: Anonymous 2010-02-26 21:36

>>80
Either way works just fine really, but beware that if a thread patches some system routines or global values, this could interfere with the other threads and mess things up. I guess those are the dangers of shared program memory. It's not nearly as bad as with the old DOS/Win3.11 shared-memory aproaches since Lisp is much more high-level, but it's still possible for an application to easily crash the whole world if it wants to.

Name: Anonymous 2010-02-26 21:52

>>78
So, it's more of a [i]fag[...] Sussman is dead. - LISPgot[i] type situation then. (Try not to mind my active ``faggot-quotes'' research.)

>>79
I can appreciate the utility of a 30MB overhead, but I like to write for small devices. I know almost everything has at least 128MB these days, but my preferred target platform only has 4.

It's okay though. There are lispy enough things that aren't so um bad.

Name: Anonymous 2010-02-26 21:59

>>82
Well, CL was never intended to be that tiny, maybe some 8MB for a full CL, but I have my doubts. R5RS' could be smaller I guess, or maybe some Lisp500 variant.

Name: Anonymous 2010-02-26 22:36

Name: Anonymous 2010-02-26 23:08

>>82

U mena faghaskalgot

Name: Anonymous 2010-02-26 23:13

Those who thinkk 30MB is nothing should consider that the entire UNIX V7 operating system was less than 10MB.

Name: Anonymous 2010-02-27 0:37

>>85
Yeha thaanks. The BBCode is not with me tonight.

>>86
Most /prog/lodytes probably don't even consider that to be an interesting fact.

Name: Anonymous 2010-02-27 1:41

>>87
Most /prog/lodytes
*gasp* all three of them?

Name: Anonymous 2010-02-27 3:56

>>86
Tinycore linux is 10mb.

Name: Anonymous 2010-02-27 5:16

>>88
Well no, only two of them.

The other one is probably the guy too obsessed with [biou]my hanux[/biou] to register a thought one way or the other.

Name: Anonymous 2010-02-27 9:00

>>90
Who wouldn't be, it's a very nice anus, Mr. The Sussman

Name: ​​​​​​​​​​ 2010-09-07 23:02

Name: Anonymous 2010-12-24 17:17

Name: Anonymous 2011-02-03 1:11


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List