Live data from Hacker News

Memory Allocators 101 – Write a simple memory allocator (2016)

arjunsreedharan.org

51–56 of 56 posts

Re: Memory Allocators 101 – Write a simple memory allocator (2016)

#51
post #18

Earlier quoted context omitted.

Not quite, (void *) is special in this regard IIRC, specifically for cases like this. It's a valid pointer but you're required to ensure that any platform requirements like alignment and size will match the requirements of what you're doing.

No, (void⁎) is not special in this way. It just makes things look nicer. The code also isn't undefined behavior... but you are really asking to hit compiler bugs! This is an easy way to confuse gcc into wrongly determining that the code has undefined behavior, and if gcc gets confused then it may determine that a code path can't be taken. Code paths that can't be taken may be deleted. The main rule here is that memor…

[deleted]

Re: Memory Allocators 101 – Write a simple memory allocator (2016)

#52

Good timing. I literally had to do this on a whiteboard in an interview about 11 hours ago. Interesting things to consider: Fragmentation prevention, real-time performance, minimizing locking(lock-free techniques, or per-thread free lists), and reusing the freed memory to contain the free list structure. I basically started out whiteboarding what the article lays out and by the end of the interview realized everythin…

If I may ask, what position/designation you were interviewing for?

Embedded/Platform engineering, working on a new OS based around a microkernel.

Re: Memory Allocators 101 – Write a simple memory allocator (2016)

#54
post #8
post #7

Earlier quoted context omitted.

So I suppose that header = (struct header_t*)(block - 1); would be UB then.

Haven't read the article but if block is void *, this won't compile because sizeof(void) is not defined. And they are probably trying to subtract the sizeof(struct header) hence the expression in your original comment.

gcc actually lets you do this: https://gcc.gnu.org/onlinedocs/gcc-8.2.0/gcc/Pointer-Arith.h...

Re: Memory Allocators 101 – Write a simple memory allocator (2016)

#55
post #30

Earlier quoted context omitted.

The moment you call sbrk or mmap, you're outside of standard C, so no. Treating a pointer as an integer in order to mess with the bits is also a violation. Aside from that, the style used here is probably OK. It is hard to say what exactly would trigger the gcc bugs, but I'm pretty sure that a recent gcc would be OK for this code.

> Treating a pointer as an integer in order to mess with the bits is also a violation. Violation of what exactly? Converting a pointer to an integer, and vice versa, is implementation defined. As long as you're not trying to write implementation-independent code, it's perfectly fine.

Sure, you can convert, but the whole point of converting is to do things that violate the C standard. In theory, a standard-conforming C implementation could have the bits of a pointer be encrypted by the CPU. There is nothing meaningful that you could do to those bits. Rounding pointers up or down for alignment is impossible in standards-conforming C code.

Re: Memory Allocators 101 – Write a simple memory allocator (2016)

#56
Giants vs Eagles https://tvvspclive.de/giantsvseagles/ https://tvvspclive.de/giantsvseagles/ Giants vs Eagles Live Giants vs Eagles Live Stream Giants vs Eagles Live Online Giants vs Eagles Live Stream Free Giants vs Eagles Live Stream Online Giants vs Eagles Live Streaming Giants vs Eagles Live Stream Reddit Giants vs Eagles Live Stream Youtube Giants vs Eagles Football Giants vs Eagles Live Football Giants vs Eagles Live Updates Giants vs Eagles Live Feed Giants vs Eagles Live Score Giants vs Eagles Live Radio Giants vs Eagles Box score Giants vs Eagles Game Live Watch Giants vs Eagles Live Giants vs Eagles Game Giants vs Eagles Tickets Giants vs Eagles Game Today Giants vs Eagles Odds Giants vs Eagles Predictions Giants vs Eagles NFL Game Giants vs Eagles Game Football Giants Eagles Live Giants Eagles Live Stream Giants Eagles Live Online Giants Eagles Live Stream Free Giants Live Stream Football Giants Football Live Stream Giants Game Live Stream Giants Football Game Today Giants NFL Game Tickets Giants Live Score Giants Live Today Giants Live NFL Giants Live Game Giants NFL Football Live Giants NFL College Football Live Giants NFL Football game Watch Giants Football game Online Eagles vs Eagles Eagles vs Giants Live Eagles vs Giants Live Stream Eagles vs Giants Live Stream Free Eagles vs Giants Live Online Eagles vs Giants Live Streaming Eagles vs Giants Live Stream Online Eagles vs Giants Live Stream Reddit Eagles vs Giants Live Stream Youtube Eagles vs Giants Football Eagles vs Giants Live Football Eagles vs Giants Game Live Watch Eagles vs Giants Live Eagles vs Giants Game Eagles vs Giants Odds Eagles vs Giants Predictions Eagles Giants Live Eagles Giants Live Stream Eagles Giants Live Stream Free Eagles vs Giants NFL Game Eagles vs Giants Tickets Eagles vs Giants Live Updates Eagles vs Giants Live Feed Eagles vs Giants Live Score Eagles vs Giants Live Radio Eagles vs Giants Game Today Eagles vs Giants Game Football Eagles Live Stream Football Eagles Football Live Stream Eagles Game Live Stream Eagles Football Game Today Eagles NFL Game Tickets Eagles NFL Football game Eagles Live Score Eagles Live Today Eagles Live NFL Eagles Live Game Eagles - NFL Football Watch Eagles Football game Online https://tvvspclive.de/giantsvseagles/ https://tvvspclive.de/giantsvseagles/ https://tvvspclive.de/giantsvseagles/ https://tvvspclive.de/giantsvseagles/ https://tvvspclive.de/giantsvseagles/
Post reply on HN