You are probably referring to a resource leak, however a resource leak specifically relates to programs that allocate memory on the heap (the free store) but fail to keep track of it. If we lose track of a heap allocation, the programmer cannot release that memory back to the system until the program terminates. The following is an example of a resource leak:
void f (unsigned x) {
void* p = malloc (x); // allocate x bytes // ... use memory
}
Each time we call this function we allocate another s bytes on the heap. But the function never releases that memory and because p is local to the function, we have no way of knowing where that memory was allocated (p will fall from scope when we return from the function). If we call this function often enough, we will eventually run out of memory.
To fix the problem, we must release the memory as soon as we are finished with it:
void f (unsigned x) {
void* p = malloc (x); // allocate x bytes // ... use memory
free (p); // release the memory
p = NULL; // zero the pointer
}
It is not necessary to zero a pointer when the pointer will fall from scope anyway, but it is considered good programming practice. What is important is that we release the memory it refers to before it falls from scope. Keeping our scopes as narrow as possible helps us to manage our resources more easily; the larger the scope, the more easily we can inadvertently introduce resource leaks, particularly when our code is maintained by several different programmers.
The problem you describe isn't necessarily a resource leak but it is clearly wasteful to allocate memory that is left unused even if we don't create a resource leak. Good programming practice dictates that we release memory as soon as we no longer require it, however allocating memory on an as-required basis can impact upon performance so it is not unusual for a programmer to allocate more memory than he needs, thus creating a reserve that can be used as and when required. Not using a reserve isn't in itself a problem, however we should endeavour to keep our reserves to a minimum and return all reserved memory to the system in a timely manner -- as soon as we no longer require it.
malloc allocate a memory section whereas memset manipulate the content of the memory section, (for example fill a memory section pointed by pointer ptr with 0, we use memset(ptr,0,sizeof(ptr_data_type)) A memory section must be allocated(using either 'malloc' or 'new' in C++) before memset can be used on it.
Phantom memory is a false memory which doesnt exist in reality .These references are available to collect byGC
In general using malloc is faster, since calloc initializes the allocated memory to contain all zeroes. If this is what you want, however, then calloc can be used. The results can vary among different operating systems and environments, though. Memory allocation in an OS that uses floating blocks in heaps, such as Microsoft Windows and MacOS, should use the OS-native memory allocators instead. "Use malloc() almost always and calloc() almost never." The reason is that the initialization to zero that calloc() performs is usually not very helpful: - The initialization to "all-bits-zero" is not necessarily the same as initialization to "all-data-zero." C says very little about the representation of values in memory, nothing at all for floating-point or pointer values. On many machines all-bits-zero representations will in fact correspond to f.p. zeroes or null pointers, but this is not guaranteed by the language and there have been machines where the correspondence did not hold. If you get in the habit of using calloc() to initialize f.p. and pointer items, you may be heading for trouble. - Usually, one allocates a chunk of dynamic memory in order to store something in it -- and when you store something in it, you'll overwrite whatever was there before. Thus, the initialization performed by calloc() is usually not needed anyhow. There are occasional exceptions where all- bits-zero initialization is helpful, but they are unusual.
Profiling refers to the act of running a program (called a "profiler") which analyzes a program you've written. The profiler will collect information about your program, such as: what functions are called, how often each is called, how much time is spent in each function, how much memory is used, etc.. This information can be used to help improve the performance of your program.
The instructions have to remain in memory at all times while the program is running. They get there by loading the entire program into memory. The CPU's instruction registers keep track of the current instruction and the next instruction.
In contiguous allocation there is no overhead during execution of a program. In noncontiguous allocation address translation is performed during execution Contiguous memory allocates single area of memory Noncontigious memory allocates several memory areas - one memory are to each component of a process
It is commonly called "virtual memory".
Dfference between contiguous and noncontiguous1) In contiguous allocation there is no overhead during execution of a program.1)In noncontiguous allocation address translation is performed during execution2)Contiguous memory allocates single area of memory2)Noncontigious memory allocates several memory areas - one memory are to each component of a process
Allocation is performed by OS while memory detection is done by BIOS.
no , it is called random access memory
The memory manager is the program responsible for managing memory allocation and deallocation in an operating system. It keeps track of which memory is available and allocates it to processes based on their needs. It also handles swapping data between main memory and secondary storage when the system runs low on physical memory.
The kernel The kernel is the hub of the operating system: it allocates time and memory to programs and handles the filestore and communications in response to system calls. The shell The shell acts as an interface between the user and the kernel. When a user logs in, the login program checks the username and password, and then starts another program called the shell.
When a function gets called, the processor first stores the address of the calling function in a structure called activisation structure and jumps to the called function. Then it allocates the memory for the local variables and initializes them. Then it does the processing in that function. After that it deallocates the memory allocated for the local variables and returns to the calling function. When a function gets called, the processor first stores the address of the calling function in a structure called activisation structure and jumps to the called function. Then it allocates the memory for the local variables and initializes them. Then it does the processing in that function. After that it deallocates the memory allocated for the local variables and returns to the calling function.
I guess it's functions malloc and free, what are you thinking of.
part of OS that allocates memory,CPU and other resources
You can determine the amount of memory a device driver allocates for itself and its data by using the MEM command with the \M filename option.A+ Guide to software fourth edition page 311
When calloc is called, it first allocates memory blocks equal to the product of the given number of elements and size of each element. It then initializes all bytes in the allocated memory to zero. The memory diagram would show a contiguous block of memory with its contents set to zero after the allocation.