top | item 32219425

(no title)

yb303 | 3 years ago

I had a 1 minute look at the "optimized" C code - it's calling malloc for every word.

discuss

order

Arnavion|3 years ago

>I had a 1 minute look at the "optimized" C code - it's calling malloc for every word.

Neither simple.c nor optimized.c call malloc "for every word". They only call malloc when inserting a previously-unseen word into the counting map.

Areading314|3 years ago

Doesn't malloc return a pointer? Sounds unsafe

yb303|3 years ago

That's not the point. It's perfectly safe and there's nothing else in C. The point is you don't have to call this function for every single word. It takes time and pointer increment doesn't

centilliard|3 years ago

Ooo... spooooky pointers... ancient prophecies speak of the Earth splitting in half and swallowing everyone who's ever thought about allocating memory.