Debugging Pro-Tip: Malloc() Errors

On Friday, I spent a number of hours trying to run down an error in a fairly substantial piece of code. All I really knew was that I kept getting an error that said something like: *** glibc detected *** ./my_program: malloc(): memory corruption: 0x0000000002296980 *** When I pushed this piece of code through gdb, I

Patterns: Creation and Destruction Stack

Virtually 100% of all memory leaks are preventable, assuming the programmer knows where to look. In many cases, the leaks occur because a programmer has failed to destroy what he has created, but it can become more complicated than that. Creation Stack: The Order Matters In many cases, we allocate memory as we use it, and

Linux + C – Introducing Pointers

You've likely noticed the * symbol showing up in our code. Time to look at what that means. Value and Reference There are two kinds of data in a program: values, references to a value. We already know how to create a value object, because basic data types such as int and char are value objects.

CS 101 – Program Execution Cycle

In simple terms, a program is a series of instructions to be executed in a particular order. The program execution cycle is a method by which we attempt to improve the speed of this execution series. Mono-Cycle Instructions We have previously discussed the concept of the clock, which is used to coordinate all operations in a

CS 101 – Get on the Bus

As we have discussed previously, computers operate as a huge array of switches, which operate in the on and off positions. What, we can reasonably ask, defines whether the switch is off or on? The answer: electricity. Buses: Wires connecting switches The average computer contains many hundreds of feet of wire, designed to carry electrical charges between

CS 101 – Basic Components

A computer can be loosely defined as consisting of three parts: the CPU, Memory, and Input/Output devices. We will be looking at these components today. CPU The Central Processing Unit, or CPU, is the brain of the computer. It handles all the logic and math that allows your computer to function. The ALU (Arithmetic-Logic Unit) performs arithmetic