new operator The new operator denotes a request for memory allocation on the Heap. If sufficient memory is available, new operator initializes the memory and returns the address of the newly allocated and initialized memory to the pointer variable. Syntax to use new operator: To allocate memory of any data type, the syntax is: pointer-variable = new data-type; Here, pointer-variable is the pointer of type data-type. Data-type could be any built-in data type including array or any user defined data types including structure and class. Example: // Pointer initialized with NULL // Then request memory for the variable int *p = NULL; p = new int; OR // Combine declaration of pointer // and their assignment int *p = new int; Initialize memory: We can also initialize the memory using new operator: pointer-variable = new data-type(value); Example: int *p = new int(25); float *q = new float(75.25); Allocate block of m...
https://www.bogotobogo.com/cplusplus/C11/1_C11_creating_thread.php Processes are independent while thread is within a process. Processes have separate address spaces while threads share their address spaces. Processes communicate each other through inter-process communication. Processes carry considerable state (e.g., ready, running, waiting, or stopped) information, whereas multiple threads within a process share state as well as memory and other resources. Context switching between threads in the same process is typically faster than context switching between processes. Multithreading has some advantages over multiple processes . Threads require less overhead to manage than processes, and intraprocess thread communication is less expensive than interprocess communication. Multiple process concurrent programs do have one advantage: Each process can execute on a different machine ( distribute program ). Examples of distributed programs are file serve...
Comments
Post a Comment