4

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.

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
Ids
  • 198
  • 1
  • 12
  • Some people write(2) that way all the time(2), as it makes it clear(1)er what they are trying to stat(2)e. – ChrisH Jul 11 '12 at 23:30

3 Answers3

9

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]
ouah
  • 142,963
  • 15
  • 272
  • 331
3

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).

Phill.Zitt
  • 343
  • 2
  • 16
1

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 e.g. 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.

pb2q
  • 58,613
  • 19
  • 146
  • 147
  • I believe he is referring to the POSIX definition of malloc. It's not just Linux specific. –  Jul 11 '12 at 20:27