Want this question answered?
variable is a name that allocates the memory space where you store some data Hardly. Names do not allocate memory space *sigh*
No, because the O/S call to allocate memory can allocate either physical memory OR swap file space. It's under O/S control, not the application.
No, because the O/S call to allocate memory can allocate either physical memory OR swap file space. It's under O/S control, not the application.
To dynamically allocate memory, use the following function (stdlib.h I believe): int *variable1 = malloc(sizeof(int));
A pointer is a reference to a location in memory that is a primitive type in C and other low-level languages. An example use would be if you wanted to store data at run-time, you would have to allocate memory using the malloc function, an you would access that memory area using a pointer Example (modified from http://www.cplusplus.com/reference/clibrary/cstdlib/malloc): #include <stdio.h> #include <stdlib.h> int main () { int i,n; char * buffer; // Declare a pointer to a char printf ("How long do you want the string? "); scanf ("%d", &i); // Get input from user and store in i // Allocate space for i+1 characters buffer = (char*) malloc ( sizeof( char[i+1] ) ); // buffer should now contains a pointer to this location if (buffer==NULL) exit (1); // Memory allocation failed, abort for (n=0; n<i; n++) buffer[n]=rand()%26+'a'; buffer[i]='\0'; printf ("Random string: %s\n",buffer); free (buffer); // Release allocated memory return 0; }
All variables (and constants) must be declared before they can be used. This is so the compiler knows exactly how much memory to allocate to the variable, as the declaration tells the compiler exactly what the variable's type is.
RAM (Random Access Memory) is a physical chip that is inserted into your motherboard inside your computer. Allocating 'space' on your computer to act as RAM is called 'virtual memory'. Virtual memory can be increased as long as you have room on your hard drive to allocate. Physical memory can be increased by replacing the chips on your motherboard. Quite simply, to allocate an unlimited amount of space for RAM would only depend on how large your hard drive(s) were or how many slots on your motherboard existed.
I believe you can attempt to allocate as much as you want, but if you try to take more physical memory than your machine has then malloc will instead return a null pointer
A pointer is a variable whose value is the address to another variable. Pointers are most commonly used to dynamically allocate memory off of the heap instead of defining all of your variables at compile-time.
In Java we need not allocate memory manually. The JVM would take care of allocating as much memory that your objects would require automatically.
A buffer overflow occurs when a program attempts to write data to a buffer, but exceeds the boundaries of the buffer, similar to Java's "Array Out of Bounds Exception." This could happen with poorly written code that fails to check for the end of the buffer, or it could be exploited maliciously. One exploitative example would be a stack buffer overflow, in which data is copied to a local variable on the stack. But if the data is larger than the local variable can contain, the extra data will "spill over" onto nearby memory. This would allow one to overwrite data that was not intended to be altered.
alloc :- to allocate memory. calloc :- to free the memory.