Is malloc deterministic?

后端 未结 7 1543
一整个雨季
一整个雨季 2020-12-14 07:05

Is malloc deterministic? Say If I have a forked process, that is, a replica of another process, and at some point both of them call the malloc

7条回答
  •  太阳男子
    2020-12-14 07:48

    The C99 spec (at least, in its final public draft) states in 'J.1 Unspecified behavior':

    The following are unspecified: ... The order and contiguity of storage allocated by successive calls to the calloc, malloc, and realloc functions (7.20.3).

    So it would seem that malloc doesn't have to be deterministic. It therefore isn't safe to assume that it is.

提交回复
热议问题