Tuesday, December 13, 2011

Understanding Pointers and Memory in C and C++

Pointers and dynamic memory allocation are some of the most confusing topics for new programmers! But don't be afraid of them--they're very useful concepts because they unlock the ability for your program to continually request and use new memory. In reality, a pointer is just a way to refer to the PLACE that a variable is stored, which lets you ask for more places to store variables.  Imagine a video game with unending levels--each level needs new memory. Pointers let you ask the system for new memory for each new level.

(Basic) Introduction to Pointers (C version) - What are pointers? Why do we care?

(Intermediate) - Memory Allocation Basics and, How to Allocate a Multidimensional array - Once you know the basics of what a pointer is, the next step is to use pointers to store arbitrary amounts of memory

(Intermediate)  - Understanding how Memory is really Laid Out - If you're having trouble getting your head around what memory really looks like--this article is the answer

(Intermediate)  - Debugging Common Problems with Memory Allocation - Pointers are great, but they do make it easy for your program to crash--learn how to fix it
 
(Advanced)  - Using auto_ptr to avoid memory leaks - Once you start allocating memory, you need to be able to free it, preferably automatically. Learn how in this article.

(Advanced, Linux)  - Using Valgrind to Find Memory Leaks - Learn how to track down memory leaks automatically using a free Linux-based tool

Pointers really are fun!
 
Alex

49 Dover St. #37, Somerville, MA 02144, USA



Centos 7 reset root/ any user lost password / lockout due to cant remember password

1. Need to be in front of the terminal. (Physically if not vm). 2. Reboot the server 3. Press 'e' in the GRUB2 boot screen. 3. bunch...