C language Free () function: frees dynamically allocated memory space
header file:
The free () function is used to release the dynamically allocated memory space, and its prototype is:
Free () frees up the memory space allocated by malloc (), Calloc (), realloc () so that other programs can use it again.
The "parameter description" PTR is the address of the memory space that will be freed.
Free () Only frees the dynamically allocated memory space and does not release any memory. The following is the wrong wording:
int a[10];
// ...
Free (a);
If the memory space that PTR points to is not allocated by the above three functions or has been freed, then the call to free () can occur unpredictably.
If PTR is NULL, then free () has no effect.
Note: free () does not change the value of the PTR variable itself, and it still points to the same memory space after the call to free (), but the memory is now invalid and cannot be used. Therefore, it is recommended that the value of PTR be set to NULL, for example:
code example:
#include <stdlib.h>
int main ()
{
int * buffer1, * buffer2, * BUFFER3;
Buffer1 = (int*) malloc (100*sizeof (int));
Buffer2 = (int*) calloc (100,sizeof (int));
Buffer3 = (int*) realloc (buffer2,500*sizeof (int));
Free (buffer1);
Free (BUFFER3);
System ("pause");
return 0;
}
C language GetPageSize () function: Get the memory paging size
header file:
To define a function:
size_t getpagesize (void);
Function Description: Returns the size of a paging in bytes (byte). This is the paging size of the system and is not necessarily the same as the hardware paging size.
Return value: Memory paging size.
Additional note: The return value on the Intel x86 should be 4096bytes.
Example
#include <unistd.h>
Main () {
printf ("Page size =%d\n", getpagesize ());
}