1753925 Members
9255 Online
108810 Solutions
New Discussion юеВ

memory question

 
Jay Cantwell
Regular Advisor

memory question

How is memory allocated when starting up a Cobol, C, or any other language program. Is it allocated in certain areas (partitions) or is the memory allocated as is needed by the program. Is this memory taken from RAM or another pool of memory. Currently I have 1.7 Gig of ram (determined from glanceplus and the 'top' command)...

thanks...Jay
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor

Re: memory question

This question is really too general to answer. It depends upon many factors and to an extent depends upon is the code 32-bit or 64-bit.

Your executable can de roughly divided into 3 sections (text -- the actual instructions which might be shared with other processes; data --- just what it sounds like; and bss -- essentially uninitialized data); it gets more complicated because local variables (i.e. auto storage class varies local to a function) are generally allocated from the stack while static storage class local variables are in the 'data' segment. In 32-bit world each of these fall , by default, into separate 1GB quadrants. There is also 'shared memory' which can be shared among a group of related processes. I should also mention that processes can dynamically allocate memory 'on the fly' using the sbrk() system call -- which is usually invoked from the higher-level malloc() and related funcions. Dynamic memory allocation is extremely common is languages like C or C++ but less common in languages like COBOL.


Note that the process really doesn't care how much physical memory you have --- although from a performance perspective it does matter --- but only upon the amount of virtual memory (RAM + SWAP) available. If a given program cannot load, it might be because the kernel parameters maxtsiz (text), maxdsiz (data), or maxssiz (stack) limits are exceeded. These parameters also have 64-bit counterparts that apply to 64-bit processes.


If it ain't broke, I can fix that.
Stefan Farrelly
Honored Contributor

Re: memory question

Memory is allocated depending on how the Cobol, C or other language program asks for it.

For example, using the malloc() C call you can request just a huge chunk of memory, from 1MB to hundreds of MB.
If you write a simple C program which simply declares a string variable of 80 characters then it will use that much memory, plus some more depending on how many lines of code you have.
Or if you request shared memory then its of a fixed size, and it shows using the ipcs command (ipcs -m).

All of the above are taken from RAM. As these programs get loaded into memory free ram goes down (vmstat command shows free pages of memory). The goal will be to ensure you never run out of memory, or else performance degrades signicicantly so keep an eye on the free total from vmstat.
Im from Palmerston North, New Zealand, but somehow ended up in London...
Michael Steele_2
Honored Contributor

Re: memory question

Hi:

See attached Memory Management White Paper and refer to /usr/share/docs/mem_mgt.txt
Support Fatherhood - Stop Family Law