Sunday 20 November 2011

How can I keep my program from running out of memory? in C programming

How can I keep my program from running out of memory?

If you are using a lot of static data, you might want to think about using dynamic memory allocation instead. By using dynamic memory allocation (with the malloc() and calloc() functions), you can dynamically allocate memory when you need it and release it (via the free() function) when it is no longer needed. This helps in a couple of ways. First, dynamic memory allocation allows your program to be more efficient because your program uses memory only when necessary and uses only the memory it really needs. You don’t have a lot of unused memory unnecessarily being taken up by static and global variables. Second, you can check the return value of the malloc() and calloc() functions to trap for situations in which you might not have enough memory.

If your program is extremely large, you might want to use an overlay manager or a DOS extender, or you might want to use alternative memory allocation schemes such as EMS or XMS (see FAQs XVIII.13 and XVIII.14 for further discussion on these topics).

Cross Reference:

XVIII.11: I get the message DGROUP: group exceeds 64KB during my link. What’s wrong?
XVIII.13: My program is too big to run under DOS. How can I make it fit?
XVIII.14: How can I get more than 640KB of memory available to my DOS program?
XVIII.15: What is the difference between near and far?

No comments:

Post a Comment