Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

static variables - VSZ and RSZ size

tanmay patil
Occasional Advisor

static variables - VSZ and RSZ size

Hi ,

If we have static global variables in our program , will we have increase the VSZ/RSZ memory of our program
4 REPLIES
James R. Ferguson
Acclaimed Contributor

Re: static variables - VSZ and RSZ size

Hi:

If I understand your question, you need to examine:

# ulimit -a

...with regard to 'data' (for the heap) and perhaps (though unlikely) for the 'stack'. These are your "soft" limits.

The kernel parameters 'maxdsiz' and 'maxssiz' govern the "hard" limits for these respectively, for 32-bit processes. 'maxdsiz_64bit' and 'maxssiz_64bit' are the hard limits for 64-bit processes.

http://docs.hp.com/en/B2355-60130/maxdsiz.5.html

http://docs.hp.com/en/B2355-60130/maxssiz.5.html

http://docs.hp.com/en/B2355-60130/sh-posix.1.html

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: static variables - VSZ and RSZ size

>If we have static global variables in our program, will we have increase the VSZ/RSZ memory of our program

If you have static storage duration variables, these increase your VSZ.

As JRF says, if these are large, you may have to increase maxdsiz.
tanmay patil
Occasional Advisor

Re: static variables - VSZ and RSZ size

Hi ,

Actually we are trying to optimise memory taken by processes .
Some of static variables are arrays which are initialised at the declaration itself and used by all functions in the file .
Is there way to optimise this memory consumption ? If we make these arrays as local , it would be problem for runtime allocation on stack .

Also how do we typically optimise the memory taken by processes .
Also we are using pmap to study the memory utilisation . is there better tool
Highlighted
Dennis Handly
Acclaimed Contributor

Re: static variables - VSZ and RSZ size

>we are trying to optimise memory taken by processes.

How many users of the program are running at once? How much memory?

>Some of static variables are arrays which are initialised at the declaration itself and used by all functions in the file.

Is this read only data? If so, add const.

>If we make these arrays as local, it would be problem for runtime allocation on stack.

The stack would have to be made big enough and you would have to initialize your arrays on every call.

>how do we typically optimise the memory taken by processes.

Allocate it on the heap when you need it.

>is there better tool

For static storage, you can just use size(1).
For heap, you can use mallinfo(3).