Thursday, December 02, 2004

New things I'm learning

I'm trying to write a managed code wrapper for some libraries written in VC++ 6. I have sample code, also written in C++. I'm a bit rusty on C++, so I dusted off a few of my books, to try to learn a bit more about this language. What I put here is for anybody's benefit, but mostly for my own memory.

I started seeing function declarations like this:
void myFunction(int varA, void *varB)

What's this *varB? Well, in VB.Net, it's passing the variable 'by reference'. You'ld do it like so:
myFunction(ByVal varA As Integer, ByRef varB As Object)

In C++ this is called indirection, and varB would be called a pointer. C++ can use this to access stuff off the heap, as opposed to the stack.

Whoa!!! What are you talking about now!?!?

More fun stuff I learned. The term stack refers to the area of memory allocated to your program. The term heap refers to the computer's virtual memory. Stack is like inside your sandbox, all alone, safe and sound. Heap is the rest of the playground with all the other children, where you might get your toes stepped on.

Hope that clears things up for us all.

No comments: