C - Design your own free( ) function

前端 未结 8 1553
感动是毒
感动是毒 2020-12-29 08:27

Today, I appeared for an interview and the interviewer asked me this,

  1. Tell me the steps how will you design your own f
8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-29 08:58

    Tell me the steps how will you design your own free( ) function for deallocate the allocated memory.

    #include 
    #undef free
    #define free(X) my_free(X)
    
    inline void my_free(void *ptr) { }
    

    How can it be more efficient than C's default free() function ?

    It is extremely fast, requiring zero machine cycles. It also makes use-after-free bugs go away. It's a very useful free function for use in programs which are instantiated as short-lived batch processes; it can usefully be deployed in some production situations.

    What can you conclude ?

    I really want this job, but in another company.

提交回复
热议问题