alloc, malloc, and alloca — What's the difference?

前端 未结 3 820
逝去的感伤
逝去的感伤 2021-01-31 04:07

I was under the impression that alloc in Objective-C (when we invoke [anyObject alloc] is actually implementing C function malloc and the

3条回答
  •  孤街浪徒
    2021-01-31 04:28

    I don't remember the verbatim statement from the book C++ Primer, but there is a major difference between the functions. For example new in C++ allocates memory, but it also constructs the data into the memory. The std::allocator allocates memory, but doesn't call any constructor. The same is true for these C functions. One allocates but doesn't construct. One allocates and construct.

提交回复
热议问题