View Single Post
  #4   Spotlight this post!  
Unread 12-12-2013, 14:19
RyanCahoon's Avatar
RyanCahoon RyanCahoon is offline
Disassembling my prior presumptions
FRC #0766 (M-A Bears)
Team Role: Engineer
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Mountain View
Posts: 689
RyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond repute
Re: Does anyone know someone with extensive knowledge of c#?

That's a very broad topic to talk about in any kind of concrete detail. I'll start with describing the basic concepts, and then maybe you can provide a piece of example code you're having trouble understanding, describe a piece of code you're trying to create, or follow up with a more specific question that I can help you with.

Pointers are, at their simplest, a reference to a location in the computer's memory. Since the variables in a program are each stored at a certain location in memory, pointers are often used to pass references to a variable to other parts of a program [sorta like ref method parameters in C#]. I'm pretty sure the pointers used by emguCV aren't for this purpose, though.

The other main use for pointers (and the way emguCV is using them) is to refer to objects that are created at runtime. For example, when you ask emguCV to create an image of a certain size, it will claim enough memory to store the data for that image. The way emguCV remembers where the image data is stored in memory is by keeping a pointer to it.

When a program claims memory to store an object, it's also responsible for releasing that claim on that memory when it's done with it. If the program doesn't do this, it's called a memory leak, and this is bad. For example, if you create an image each time you process a camera frame, but never release the memory associated with that image when you're done processing that frame, then your program will start using more and more memory over time, since it can't reuse any of that memory when it creates more images for processing new frames.

The reason you don't have to worry about this with C# is that C# uses something called garbage collection, where it automatically keeps track of which objects you're still using and releases an object's memory once your program is done with it.

If you use the CvInvoke class members from emguCV, you're calling directly to the unmanaged functions and you'll get pointers back that you'll have to manage and remember to release manually. However, part of the power of emguCV is that it'll do this memory management automatically, by leveraging C#'s memory management. To use these features, use classes like Image<>.

To talk briefly about handles: handles are another type of reference to an object in memory, but when you call something a "handle," the value of this reference is not necessarily the actual memory address of the object. The value of handle is understood by the code that gave that handle to you, but you shouldn't try to interpret the value yourself. For example, with emguCV, suppose you use the CvInvoke class and get an IntPtr back. You then pass this IntPtr value around your program so that whenever you call another image processing function, emguCV will know which image it's supposed to process. The actual value of the IntPtr means nothing to your program, though, and reading from the memory it points to won't necessarily yield any meaningful data, so these IntPtrs are functioning more like handles. Handles are sometimes called "opaque references" because you can't "see through" the reference to "look at" the actual object.
__________________
FRC 2046, 2007-2008, Student member
FRC 1708, 2009-2012, College mentor; 2013-2014, Mentor
FRC 766, 2015-, Mentor