Hacker News new | past | comments | ask | show | jobs | submit login

> Oh, and because you've been such a tough-guy you only get to use malloc...once. In the main function

Oh yeah? How about I just don't use malloc then:

    static char ALLTHEFUCKINGMEMORY[1024*1024*1024];
    static size_t NEXTBYTE = 0;
    void *myAlloc(size_t size) {
        void *ptr = &ALLTHEFUCKINGMEMORY[NEXTBYTE];
        NEXTBYTE += size;
        if (size & 3) NEXTBYTE = (NEXTBYTE & (~3)) + 4;
        return ptr;
    }
    void myFree(void *ptr) {
        fprintf(stderr, "REAL PROGRAMMERS DON'T NEED TO FREE MEMORY\n");
        exit(-1);
    }



nice one!

for single linked list you can just use an array of the struct and borrow/return via circular list. my C is beyond the rust levels of 20y Golf 2 but I guess I won't sweat over.

An alternative solution would be cheating away and using realloc instead of malloc.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: