user3512328
user3512328

Reputation: 11

Necessity to bring program to main memory for execution?

Why is it necessary that we need to bring program in main memory from secondary memory for execution? Why cant we execute program from secondary memory? Though, it may not be possible currently, but is it possible in future, somehow by some mechanism, that we can execute the program from secondary memory directly?

Upvotes: 1

Views: 1539

Answers (3)

Mayank Srivastava
Mayank Srivastava

Reputation: 17

Main memory is used to distinguish it from external mass storage devices such as hard drives. Another term for main memory is RAM. The computer can manipulate only data that is in main memory. So, every program you execute and every file you access must be copied from a storage device into main memory.The amount of main memory on a computer is crucial because it determines how many programs can be executed at one time and how much data can be readily available to a program.

Upvotes: 0

twalberg
twalberg

Reputation: 62379

Almost all modern CPUs execute instructions by fetching them from an address in main memory identified by the instruction pointer register, loading the referenced memory through one or more cache levels before the portion of the CPU that executes the instruction even starts its work. Designing a CPU that could, for example, fetch instructions directly from a disk or network stream would be a rather large project, and performance would likely be pathetic. There's a reason you have a main memory that operates orders of magnitude faster than disk/network access, and caches between that and the actual execution cores that are orders of magnitude faster even than the main memory...

Upvotes: 2

Neeraj Lakhotia
Neeraj Lakhotia

Reputation: 1

Mostly some parts of the program is required to be accessed multiple times during the execution of the program. Reading from secondary memory every single time we needed the particular data would obviously require a lot of time.

It is better to load the program in a faster memory i.e. Main memory , so that whenever a part of program is required it can be accessed much faster. Similarly, more frequently used variables are stored in the cache memory for even faster access. It;s all about speed.

If could somehow develop affordable secondary memories that have speed as fast as the main memory, we could do without copying the whole program into main memory. However, we would still need some memory to store the temporaries during the program execution.

Upvotes: 0

Related Questions