Sponsored Content
Top Forums Programming Size of memory used by a program Post 302930423 by Don Cragun on Saturday 3rd of January 2015 04:32:35 PM
Old 01-03-2015
Assuming i, j, and k have been declared as type int; a portion of the data used by your program is:
3*dim*dim*sizeof(int) + a little bit of space for malloc() bookkeeping {for the malloc()'ed arrays} + 3*sizeof(int *)) {for the pointers} + 3*sizeof(int) {for your loop control variables}.
This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Program/ Memory Problems

I need some advise. I have an application server running several applications. When I try and start a particular application when the others are running I receive the following. This is appearing in the core file that is created. ... (1 Reply)
Discussion started by: dbrundrett
1 Replies

2. UNIX for Advanced & Expert Users

memory size under AIX

Hi, how to know size of physical memory under AIX ? Many thanks. PS : man -k memory man : 0703-310 Fichier man introuvable. uname -a AIX server1 1 5 005202DF4C00 (3 Replies)
Discussion started by: big123456
3 Replies

3. Programming

Measuring memory used by a program?

I have a Java program. I want to measure the total memory used by the program, especially the peak memory. Is there a way to do it? I have tried utilities like time (which returns 0) and top (which is not very useful) as the program does not run for long. Can anyone suggest a way to do this?... (5 Replies)
Discussion started by: spathical
5 Replies

4. Solaris

How to know the size of the program currently executing in memory

hey everybody, i am currently working on solaris 10 os on a m5000 server. my problem is when i want the exact size of a program in execution, i am unable to do it. earlier i thought the RSS field of prstat but because of its large size it cant be the size. pmap -x shows some output but it includes... (2 Replies)
Discussion started by: aryansheikh
2 Replies

5. UNIX for Advanced & Expert Users

Out of Memory error when free memory size is large

I was running a program and it stopped and showed "Out of Memory!". at that time, the RAM used by this process is around 4G and the free memory size of the machine is around 30G. Does anybody know what maybe the reason? this program is written with Perl. the OS of the machine is Solaris U8. And I... (1 Reply)
Discussion started by: lilili07
1 Replies

6. Solaris

Memory or CPU size

Is there a command or file I can look at that tells me how much real memory a machine has? A little background. In my shop we run a bunch of java programs, sometimes some of these jobs have config definitions that call for 2G. I would like to know how many I can run before I exhaust rescources. Any... (12 Replies)
Discussion started by: Harleyrci
12 Replies

7. AIX

Memory limit for C program

Greetings - I'm porting a C application to an AIX (6.1) system, and have bumped into the limits AIX imposes on memory allocation, namely the default limit of 256MB for a process. I'm aware of the compilation flag that allows an application to gain access to up to 8 memory segments (each 256MB,... (4 Replies)
Discussion started by: traviswheeler
4 Replies

8. Programming

Shared memory between two c program

i have to shared a variable between two different c programs with shared memory and i do these: int main() { int a=5,b=7; int buffer; int *point; int shmid; shmid=shmget(IPC_PRIVATE , sizeof(buffer),0666); point=(int *)shmat(shmid,NULL,0); point=a; ... (21 Replies)
Discussion started by: tafazzi87
21 Replies

9. Programming

Help regarding memory leak in this C program

I have written this code in C which reads a very large collection of text files and does some processing. The problem with this code is that there are memory leaks which I am not able to figure out as to where the problem is. When I run this code, and see the memory usage using top command, then I... (7 Replies)
Discussion started by: shoaibjameel123
7 Replies

10. UNIX for Dummies Questions & Answers

Getting file size from memory

i want to avoid writing to a file on the disk. i'd like to do this in memory. i have a situation where i'm running cat file.txt | head -l 2024 > /tmp/data.txt now, i check the size of the data.txt by doing a "du -sh /tmp/data.txt how can i get the size of "head -l 2024" WITHOUT having to... (2 Replies)
Discussion started by: SkySmart
2 Replies
CMSG_DATA(3)						   BSD Library Functions Manual 					      CMSG_DATA(3)

NAME
CMSG_DATA, CMSG_FIRSTHDR, CMSG_LEN, CMSG_NXTHDR, CMSG_SPACE -- socket control message routines SYNOPSIS
#include <sys/socket.h> void * CMSG_DATA(struct cmsghdr *); struct cmsghdr * CMSG_FIRSTHDR(struct msghdr *); size_t CMSG_LEN(size_t); struct cmsghdr * CMSG_NXTHDR(struct msghdr *, struct cmsghdr *); size_t CMSG_SPACE(size_t); DESCRIPTION
The control message API is used to construct ancillary data objects for use in control messages sent and received across sockets. Control messages are passed around by the recvmsg(2) and sendmsg(2) system calls. The cmsghdr structure, described in recvmsg(2), is used to specify a chain of control messages. These routines should be used instead of directly accessing the control message header members and data buffers as they ensure that necessary alignment constraints are met. The following routines are provided: CMSG_DATA(cmsg) This routine accesses the data portion of the control message header cmsg. It ensures proper alignment constraints on the beginning of ancillary data are met. CMSG_FIRSTHDR(mhdr) This routine accesses the first control message attached to the message msg. If no control messages are attached to the message, this routine returns NULL. CMSG_LEN(len) This routine determines the size in bytes of a control message, which includes the control message header. len specifies the length of the data held by the control message. This value is what is normally stored in the cmsg_len of each control message. This rou- tine accounts for any alignment constraints on the beginning of ancillary data. This macro might not evaluate to a compile-time con- stant. CMSG_NXTHDR(mhdr, cmsg) This routine returns the location of the control message following cmsg in the message mhdr. If cmsg is the last control message in the chain, this routine returns NULL. CMSG_SPACE(len) This routine determines the size in bytes needed to hold a control message and its contents of length len, which includes the control message header. This value is what is normally stored in msg_msgcontrollen. This routine accounts for any alignment constraints on the beginning of ancillary data as well as any needed to pad the next control message. This macro might not evaluate to a compile- time constant. EXAMPLES
The following example constructs a control message containing a file descriptor and passes it over a socket: struct msghdr msg; struct cmsghdr *cmsg; /* We use a union to make sure hdr is aligned */ union { struct cmsghdr hdr; unsigned char buf[CMSG_SPACE(sizeof(int))]; } *cmsgbuf; /* * We allocate in the heap instead of the stack to avoid C99 * variable stack allocation, which breaks gcc -fstack-protector. */ if ((cmsgbuf = malloc(sizeof(*cmsgbuf))) == NULL) err(1, "malloc"); (void)memset(&msg, 0, sizeof(msg)); msg.msg_control = cmsgbuf->buf; msg.msg_controllen = sizeof(cmsgbuf->buf); cmsg = CMSG_FIRSTHDR(&msg); cmsg->cmsg_len = CMSG_LEN(sizeof(int)); cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = SCM_RIGHTS; *(int *)CMSG_DATA(cmsg) = fd; if (sendmsg(s, &msg, 0) == -1) err(1, "sendmsg"); free(cmsgbuf); And an example that receives and decomposes the control message: struct msghdr msg; struct cmsghdr *cmsg; union { struct cmsghdr hdr; unsigned char buf[CMSG_SPACE(sizeof(int))]; } *cmsgbuf; if ((cmsgbuf = malloc(sizeof(*cmsgbuf))) == NULL) err(1, "malloc"); (void)memset(&msg, 0, sizeof(msg)); msg.msg_control = cmsgbuf->buf; msg.msg_controllen = sizeof(cmsgbuf->buf); if (recvmsg(s, &msg, 0) == -1) err(1, "recvmsg"); if ((msg.msg_flags & (MSG_TRUNC|MSG_CTRUNC)) errx(1, "control message truncated"); for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) { if (cmsg->cmsg_len == CMSG_LEN(sizeof(int)) && cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) { fd = *(int *)CMSG_DATA(cmsg); /* Do something with the descriptor. */ } } free(cmsgbuf); SEE ALSO
recvmsg(2), sendmsg(2), socket(2) HISTORY
The control message API first appeared in 4.2BSD. BSD
June 20, 2008 BSD
All times are GMT -4. The time now is 08:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy