Why don't I get a link error when I provide my own malloc and free?

前端 未结 2 1533
伪装坚强ぢ
伪装坚强ぢ 2021-01-04 23:08

I\'m trying to implement a simple fit first memory management algorithm. So I\'ve got a C file with my own

   void* malloc(size_t)

and

2条回答
  •  自闭症患者
    2021-01-04 23:49

    In my experience, it is standard practice for custom mallocs and frees to be named uniquely, such as the kernel malloc, kmalloc, and kernel free, kfree. If you're writing your own, I recommend giving a separate name for your functions.

    How are you planning to allocate memory? Most of the time you should wrap around the malloc function to provide custom functionality, but still end up using malloc in some form or another. In my opinion, this is the route you should take, so I wouldn't be too hasty to dispose of the built in malloc and free functions unless you have good reason (or strong desire) to do so. Having them named the same will interfere with this.

    This is the Minix implementation of malloc, just to give you a sense of what you're looking at.

提交回复
热议问题