3 ms·
While I agree the "segfault policy" is a bad idea, if you've got dedicated hardware for checking invalid addresses, it seems to me that you should use it. Afte
by geocar 17y ago
While I agree the "segfault policy" is a bad idea, if you've got dedicated hardware for checking invalid addresses, it seems to me that you should use it.
After all, checking the null pointer is still slow.
Combining a malloc wrapper with the segfault policy is a great way to go, for example:
void*my_malloc(int s){int *x=malloc(s);*x=0;return(void*)x;}
- tptacek 17y agoIsn't the branch in that NULL check pretty much the most predictable branch in your program?
- DarkShikari 17y agoAnd furthermore, if you're calling malloc enough to make checking your mallocs have a significant overhead, you're doing it horribly wrong.