dect
/
libnl
Archived
13
0
Fork 0

Improve performance by using malloc() over calloc() in critical places

As pointed out by Regis Hanna, a considerable performance gain can be
achieved by using malloc() over calloc() when allocating netlink message
buffers. This is likely due to the fact that we use a complete page for
each message.
This commit is contained in:
Thomas Graf 2008-05-07 13:18:30 +02:00
parent dc883cc149
commit b7c5bf98c4
2 changed files with 4 additions and 2 deletions

View File

@ -372,10 +372,12 @@ static struct nl_msg *__nlmsg_alloc(size_t len)
if (!nm)
goto errout;
nm->nm_nlh = calloc(1, len);
nm->nm_nlh = malloc(len);
if (!nm->nm_nlh)
goto errout;
memset(nm->nm_nlh, 0, sizeof(struct nlmsghdr));
nm->nm_protocol = -1;
nm->nm_size = len;
nm->nm_nlh->nlmsg_len = nlmsg_total_size(0);

View File

@ -482,7 +482,7 @@ int nl_recv(struct nl_handle *handle, struct sockaddr_nl *nla,
page_size = getpagesize();
iov.iov_len = page_size;
iov.iov_base = *buf = calloc(1, iov.iov_len);
iov.iov_base = *buf = malloc(iov.iov_len);
if (handle->h_flags & NL_SOCK_PASSCRED) {
msg.msg_controllen = CMSG_SPACE(sizeof(struct ucred));