Common Errors
The improper use of dynamic memory allocation can frequently be a source of bugs.
Most common errors are as follows:
- Not checking for allocation failures. Memory allocation is not guaranteed to succeed. If there's no check for successful allocation implemented, this usually leads to a crash of the program or the entire system.
- Memory leaks. Failure to deallocate memory using
freeleads to buildup of memory that is non-reusable memory, which is no longer used by the program. This wastes memory resources and can lead to allocation failures when these resources are exhausted. - Logical errors. All allocations must follow the same pattern: allocation using
malloc, usage to store data, deallocation usingfree. Failures to adhere to this pattern, such as memory usage after a call tofreeor before a call tomalloc, callingfreetwice ("double free"), etc., usually leads to a crash of the program.
Read more about this topic: C Dynamic Memory Allocation
Famous quotes containing the words common and/or errors:
“Whenever there are in any country uncultivated lands and unemployed poor, it is clear that the laws of property have been so far extended as to violate natural right. The earth is given as a common stock for man to labor and live on.... The small landowners are the most precious part of a state.”
—Thomas Jefferson (17431826)
“Here among the mountains the pinions of thought should be strong, and one should see the errors of men from a calmer height of love and wisdom.”
—Ralph Waldo Emerson (18031882)
Related Phrases
Related Words