简体   繁体   中英

What is the difference between malloc and malloc(3)?

While reading a hacker article on the jemalloc memory manager, the hacker keeps referring to malloc(3), not malloc. I wondered why.

Does he do so because it refers to a specific linux malloc implementation? Or simply to refer to all malloc variants, that implement the interface as described on the section 3 (libary functions) of the unix/linux manual pages? This option is my guess, want to be sure. Is there a different reason?

So, is the hacker just overly specific? Or is there a difference between malloc and malloc(3)?

The (3) part is not a reference to other documentation, article or research mentioned later in the hacker article.

malloc(3) is just a hint that malloc is a part of the section 3 of the man pages. The section 3 is where are the library functions. This is by opposition to the section 2 of the man pages where are the syscalls. There is no malloc(2) .

For example:

fwrite is a library function so sometimes written as fwrite(3)

write is a syscall so sometimes written as write(2)

If you run the command:

$ man man

it will tell you

   1   Executable programs or shell commands
   2   System calls (functions provided by the kernel)
   3   Library calls (functions within program libraries)
   4   Special files (usually found in /dev)
   5   File formats and conventions eg /etc/passwd
   6   Games
   7   Miscellaneous  (including  macro  packages and convenâ
       tions), e.g. man(7), groff(7)
   8   System administration commands (usually only for root)
   9   Kernel routines [Non standard]

Preface: My unix is weak.

I believe that it is simply a reference to the section 3 library.

( from the jargon file )
References such as malloc(3) and patch(1) are to Unix facilities (some of which, such as patch(1), are actually open source distributed over Usenet).

It looks like the author is simply being very specific.

Specifying the reference to section 3 of the man pages is often useful if there might be an eg shell version of the same function. For instance, man 1 printf for printf(1) vs. printf(3).

But in the case of malloc documentation should exist only in section 3.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM