Sorting is easier in memory

If you are writing a program that is going to deal with a lot of data, you need to decide where you need to keep that data while the program works with it. Most of the time, you will have two choices:

il Keep the data in files on the disk.

If you have a very large amount of data, the obvious place to put it is on disk. Computers can store far more data on disk than they can in memory. Disk storage is persistent: if you yank the power cord, the computer doesn't forget the information written on the disk. But there is one real problem with manipulating data on disk: it can be very slow.

Keep the data in memory.

Data is much quicker to access and change if it's stored in the computer's memory. But, it's not persistent: data in memory disappears when your program exits, or when the computer is switched off (unless you remember to save it to a file, in which case it becomes persistent).

Keep the data in memory

If you want to sort a lot of data, you will need to shuffle data around quite a lot. This is much faster in memory than on disk.

Of course, before you sort the data, you need to read it into memory, perhaps into a large number of individual variables:

Yo* need to moVe ■the lines of data in the resi*lts.t*t f ile into mtmCK^i before sovt it-

V°u have lots of lines of data, so you'll need lots of variables... right?!?

If you want to sort a lot of data, you will need to shuffle data around quite a lot. This is much faster in memory than on disk.

Of course, before you sort the data, you need to read it into memory, perhaps into a large number of individual variables:

V°u have lots of lines of data, so you'll need lots of variables... right?!?

You are going to have a problem if you attempt to move all those lines of data into the computer's memory. What type of problem do you think you'll have?

po vou -------j tujpboavd?!? Because that s too many variables

Was this article helpful?

0 0

Post a comment