Ids
Ids

Reputation: 208

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.

Upvotes: 5

Views: 389

Answers (3)

pb2q
pb2q

Reputation: 59667

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.

Upvotes: 1

Phill.Zitt
Phill.Zitt

Reputation: 343

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

Upvotes: 3

ouah
ouah

Reputation: 145919

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]

Upvotes: 10

Related Questions