Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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


>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.


Doesn't malloc return a pointer? Sounds unsafe


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


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




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

Search: