On 1/05/11 2:53 PM, Dmitry Olshansky wrote:
Ehm.. Well, first things first: you shouldn't use classes for lightweight & plain data things like vectors. There are structs for that. In general, structs are value-like objects living on the stack while classes are reference-like objects living on the heap. Your current code is going to allocate on GC heap new vector in every GetColumn and I suspect also when adding two vectors.
structs don't live on the stack. They live wherever they are told to. In fact most structs will live in the heap as parts of class objects, or other heap-allocated objects such as dynamic arrays or AAs. The stack is for local variables and other things to do with the local scope.
While struct objects *can* go on the stack, it is false to say that structs live on the stack and classes live on the heap. The type of an object (value type or reference type) is orthogonal to its storage location and the two should not be conflated.