News for hackers. Stuff that matters.
Re:Writing a Simple Garbage Collector in C by jimbob45 on Saturday December 14, 2019 @11:34PM (#21794472)
Would love to see a Windows-based version of this article. No sbrk() or mmap() in Windows makes the implementation a bit different.
Re:Writing a Simple Garbage Collector in C by userbinator on Sunday December 15, 2019 @12:13AM (#21794589)
Windows has VirtualAlloc which is like mmap, but you're right that it has no concept of a "break"; in fact, the stack of the main thread is below (most of) the heap in Windows, below the executable itself. In pseudopictorial form,

    Linux/most other *nix:
    | executable | libs | heap---> <--- stack |

    Windows:
    | <--- stack | heap | executable | heap | libs | heap---> |
Re:Writing a Simple Garbage Collector in C by marvy on Sunday December 15, 2019 @12:38AM (#21794665)
Does this picture change much between the 32-bit vs 64-bit world? How about if there are few vs many threads? (For instance, if a program on 32-bit windows spawns hundreds of threads, surely you can't squeeze all those stacks below the heap, can you?)
Re:Writing a Simple Garbage Collector in C by userbinator on Sunday December 15, 2019 @01:16AM (#21794780)
The 64-bit address space is much bigger and even more unpredictable when there's ASLR, but in my experience the main thread's stack still ends up below the executable; they're just much farther apart. I believe other threads' stacks also fit somewhere below, but with 32-bit it will start allocating them in areas that would've otherwise been heap once the area below the executable runs out.
Re:Writing a Simple Garbage Collector in C by marvy on Monday December 16, 2019 @10:28PM (#21810248)
thanks!
Re:Writing a Simple Garbage Collector in C by zerr on Sunday December 15, 2019 @05:56AM (#21795584)
Btw brk and sbrk are deprecated in POSIX anyway.