How to Think About Variables in C

C is memory with syntactic sugar and as such it is helpful to think of things in C as starting from memory. One of the pieces that I think is often overlooked is variables and data types. If you have the right mental model for variables and data types it makes other concepts in C, and other langauages, easier. Let’s start with three definitions. Read more…

|   

Basics of Function Pointers in C

This post is very detailed because I am attempting to create a mental model to help beginners understand the syntax and basics of function pointers. If you are ok with detail happy reading.

Function pointers are an interesting and powerful tool but their syntax can be a little confusing. This post will going into C function pointers from the basics to simple usage to some quirks about function names and addresses. In the end it will give you an easy way to think about function pointers so their usage is more clear. Read more…

Is C Pass by Value or Reference?

Pass by Value

In the strictest sense of the word, everything in C is pass-by-value. This often confuses beginning C programmers, especially when it comes to pointers, arrays, and structs. So what do we mean when we say pass-by-value and pass-by-reference.

When we pass-by-value we are passing a copy of the variable to a function. When we pass-by-reference we are passing an alias of the variable to a function. C can pass a pointer into a function but that is still pass-by-value. It is copying the value of the pointer, the address, into the function. In C++ a reference is an alias for another variable. C doesn’t have this concept. Read more…

Basics of Memory Addresses in C

Memory Addresses

It is helpful to think of everything in C in terms of computer memory. Let’s think of computer memory as an array of bytes where each address in memory holds 1 byte. If our computer has 4K of memory for example, it would have 4096 elements in the memory array. When we talk about pointers storing addresses, we are talking about a pointer storing an index to an element in the memory array. Dereferencing a pointer would be getting the value at that index in the array. All of this is of course a lie. How operating systems handle memory is much more complex than this. Memory is not necessarily contiguous and it is not necessarily handed out sequentially. But the analogy provides an easy way to think about memory in C to get started. Read more…

The 5-minute Guide to C Pointers

Pointers, Addresses and Dereferencing

What is a pointer? What is a memory address? What does dereferencing a pointer mean?

A pointer is a variable that holds the location of, literally the address-of, a variable stored in computer memory. An address is the actual address-of a variable in the computer memory. Dereferencing a pointer means getting the value stored in the memory at the address which the pointer “points” to. Read more…

Android Image Downloading and Caching

One of the utility classes we created for the Singly Android SDK is a remote image downloader and cache. We wanted to be able to download images from remote sites, store them locally, and cache them in memory. We also wanted to be able to limit the number of concurrent images we were downloading, avoid duplicate downloads, avoid retrying bad images, and more importantly optimize the images for memory consumption. In this post we will detail our RemoteImageCache class that can be dropped into any Android application to enable easy remote image downloading and caching. Read more…

Read Android Data Folder Without Rooting

I got my new galaxy s3 and I am all excited doing new android development. I fire up the adb shell to look around and I see this:

Grrrr. Ok so I can’t access the data folder because it is read protected. What do I do now? I can root the phone, but I don’t really want to do that for various reasons. All I really want is to see into my data folder application directories, be able to remove test files such as databases and preferences. Read more…