answersLogoWhite

0

Variables need only be defined before they are actually used, so there is no need to define them before calling any functions that don't actually use them, including clear screen functions. However, by moving all the declarations to the top of the function, and sorting them in descending order of size, you minimise memory consumption by eliminating any unnecessary padding for alignment purposes.

For example, suppose your function uses the following variables in this order:

char ch1;

int i1;

char ch2;

int i2;

char ch3;

int i3;

char ch4;

int i4;

Assuming an int is 4 bytes, this will consume up to 32 bytes in total, because the int variables should ideally be aligned upon 32-bit boundaries. Thus each char variable wastes 3 bytes. By sorting them from largest to smallest, you reduce the consumption to just 17 bytes:

int i1;

int i2;

int i3;

int i4;

char ch1;

char ch2;

char ch3;

char ch4;

Saving just 15 bytes for one function may seem insignificant, but when applied to every function those savings can be quite substantial. The more memory you save, the smaller your code will be, and therefore the quicker it will execute.

The only problem with doing this is that variables are then scoped to the function, rather than to the statement bodies that actually use them. However, once a function has been fully debugged, it makes sense to optimise its memory consumption and then test one more time to ensure no bugs have crept in.

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

Why do you use clrscr after the declaration of variables in c language?

Most programmers declare variables at the top of a function and place them in descending order of size to minimise wasted memory from alignment. However, there is no specific requirement to clear the screen before processing those variables. In fact, it's best not to clear the screen at all. Ideally, console programmers should leave things exactly as they found them, and either append their program's output to the current console, or toggle modes as required, restoring the original mode when the program ends.


What are the screen function?

Touch screen computers are used for: visual communication, more realistic qualities in a game when being played and more ease and comfort when being used


How do manufacturers define the size of a 42 or 36 inch television?

Screen size is measured diagonally in inches between opposite corners of the screen.


What is the function of Page Down?

you click the screen


Why wont your c plus plus program stay open?

If you are talking about the program executing, but the output screen being displayed for a flash and then disappearing, I suggest adding getch() or getchar() function at the end of your main function. This will make sure that the output screen waits for you to press a character before the program terminates.


What is the meaning of conio in C?

Hi, Conio.h is a header file which have functions declaration. One of them is clrscr() function. This function have its prototype in conio.h. clrscr() function is used to clear the screen. Thus, whenever u called clrscr() function u r required to define conio.h header file in your program.... Similarly there are many functions in conio.h.... Hope it will help u....


What is the function of buttons?

Expands the screen to fill the window


How do you get full screen mode?

Usually function key F11 toggles full-screen mode on & off.


How does touch screen capacitive works?

touch screen capacitive works by the capacitance differential between the screen and your finger wherever there is difference in capacitance on the screen is where you are touching and the screen knows what function you are trying to do depending on what is displayed on the screen.


How far does this model swivel?

This can function as a tablet PC. That is, the screen can swivel completely around and the lid closed so that the screen is on the outside. The screen is a touch screen and can be used with a stylus.


The design view screen in access is used to define what?

for thetati poti it is used & to store the waste material in it....


What is an on screen display listing available option or function?

Tool