Newbie question on memory allocation

Newbie question on memory allocation

Post by Jayaram Mulupu » Tue, 24 Jan 1995 11:25:36




Quote:>If I have five identical programs running on 5 ttys, does each program have a
>copy of its code in memory, or do they share the same code?

each program has its own address space in memory. therefore, if each
program required, say, 1M of memory for execution, then the five programs
would require 5M of memory.

Quote:>Also, does exit() automatically release memory allocated by malloc(), or does
>free() have to be called explicitely? I would assume the entire program's heap
>would be released on exit(), but I am not sure. I am trying to figure out why
>sar only reports ~1 Meg of freemem on a 16 Meg i486 system (Microport SVr4
>v4.21).

you are correct in assuming that the entire memory of the program would be
deallocated on exit(). however, if you wish to use some memory previously
allocated by malloc() within the same program itself, then you need
to explicitly free it using free() or realloc(). also, it might be a good
idea to set the variable that was pointing to memory before free()
was called on it to NULL immediately after freeing it.
hope this helps...

jayaram.
--
                        Jayaram Mulupuru                

218 N Hyland Avenue #302                          237 Wilhelm  
    Ames, IA 50014                        Scalable Computing Laboratory

 
 
 

Newbie question on memory allocation

Post by Eric Bierm » Wed, 25 Jan 1995 10:32:45





>>If I have five identical programs running on 5 ttys, does each program have a
>>copy of its code in memory, or do they share the same code?

>each program has its own address space in memory. therefore, if each
>program required, say, 1M of memory for execution, then the five programs
>would require 5M of memory.

> ( edited ..)
>jayaram.
>--

Is this true on all systems?
On my HP I observed that code area (TEXT) is shared between identical processes.
( Using monitor to look at the free memory before and after creation of new
  processes ).

What about shared libraries ( code in shared libraries ) ?

Ravikanth.


 
 
 

1. Memory allocation and de-allocation

Hi,

I have a simple C program that allocates a bunch of memory and free's it
immediately.
When I run this program, I do not see this memory being reclaimed by the
OS(as observed
by top-5.6). A similar program on Windows NT works as expected(i.e memory
usage
decreases when memory is free'd).

Any ideas why??

Appreciate any advise you can offer..

Regards,
R

// Here is a code snippet:

int main(int argc, char** argv)
{
    if (argc == 2)
     {
        int num_chunks = atoi(argv[1])/1000;
        char **buffer[1000];

        for (i=0; i<=num_chunks; i++)
         {
            buffer[i] = (char *) malloc(1000);
            free(buffer[i]);
         }
       return 0;
    }
  printf("Usage!! %s <memory size> \n",argv[0]);

2. tcsh 6.03 and AIX 3.2.3 (extended)

3. Question about linux memory allocation

4. qmail problem

5. Question on Memory Allocation

6. term+archie

7. Kernel memory allocation question

8. IBM Laser 4019

9. i810 memory allocation question

10. memory allocation by OS memory manager

11. x86 driver/kernel question: larger phys.contiguous memory allocation?

12. Question about linux memory allocation

13. Memory allocation question