Search code examples
cmanpage

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.


Solution

  • 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]