malloc returns a void pointer to the allocated space, or NULL if there is insufficient memory available. To return a pointer to a type other than void, use a type cast on the return value. The storage space pointed to by the return value is guaranteed to be suitably aligned for storage of any type of object. If size is 0, malloc allocates a zero-length item in the heap and returns a valid pointer to that item. Always check the return from malloc, even if the amount of memory requested is small.

malloc 返回一个指向已分配空间的 void 指针,如果内存不足,则返回 NULL。若要返回指向非 void 类型的指针,请在返回值上使用类型转换。由返回值指向的存储空间保证适当地对齐以存储任何类型的对象。如果 size 是 0,malloc 会在堆中分配一个零长度的项目,并返回一个指向该项目的有效指针。即使请求的内存量很小,也要始终检查 malloc 的返回值。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐