the stack is like a very organized closet, the heap is just a pile of shit
on the floor.

On Tue, Dec 16, 2008 at 11:58 PM, Charles A. Lopez
<[email protected]>wrote:

>
>
> On Tue, Dec 16, 2008 at 11:10 AM, rbdavidson <[email protected]>wrote:
>
>>
>> Well, "value types, not datatypes" is not the only difference between
>> a struct and a class.
>>
>> Structs are allocated off the stack, classes from the heap.  Module
>> level variables in classes can have default values, in structs they
>> can't and you have to initialize values in the New().
>>
>
>
> Can you refresh my memory and explain the difference between the stack and
> heap?
>
>
>
>
>>
>> Also classes have some code overhead that structs don't which results
>> in a struct instantiating faster than a class.  Not a big deal, unless
>> you  are doing something like
>>
>> Dim myStruct(100000000) as SomeStruct
>>
>> Vrs
>>
>> dim myClass(100000000) as SomeClass
>>
>> In which case every millisecond counts and structs have the
>> advantage.  Of course, since structs are value types you can't create
>> a new struct by inheriting from an existing one.  I.e. You can't
>> create an extensible "struct hierarchy" like you can with classes.
>> This limits their usefulness to pretty particular cases.
>>
>> - RBDavidson
>>
>>
>>
>> On Dec 15, 3:18 pm, "Brandon Betances" <[email protected]> wrote:
>> > Also, the only difference between a struct and a class is that a struct
>> is
>> > used for value types, not datatypes, System.Int32 for example is a
>> struct,
>> > string is a class.
>> >
>> > On Mon, Dec 15, 2008 at 4:11 PM, Brandon Betances <[email protected]
>> >wrote:
>> >
>> >
>> >
>> > > C# performs garbage collection automatically, but you can call it
>> > > expilictly with the System.GC.Collect() method.
>> > > put it where the delete statement is.
>> >
>>  > > On Mon, Dec 15, 2008 at 3:18 PM, Alon K <[email protected]> wrote:
>> >
>> > >> Hi,
>> >
>> > >> I remember that in C++ one had to issue the following statement (or
>> > >> something similar) to clean up memory:
>> >
>> > >> delete pNode;
>> >
>> > >> and the memory address assigned to pNode will be unassigned.
>> > >> Is there something like this that needs to be done in C# ?
>> >
>> > >> So for example I have:
>> >
>> > >> pHold = pIndex;
>> > >> pIndex = pIndex->pNext;
>> > >> delete pHold; ????? <-- what can I do here
>> >
>> > >> While on the topic, I have been doing the following to create linked
>> > >> lists in the intermediate step:
>> >
>> > >> NODE* pCreate = stackalloc NODE[1];
>> > >> pIndex->pNext = pCreate;
>> > >> pIndex = pCreate;
>> >
>> > >> While I haven't programmed in C++ in a while I remember that this
>> > >> could be done directly in C++:
>> >
>> > >> pIndex->(*pNext) = new NODE;
>> > >> pIndex = pIndex->pNext;
>> >
>> > >> Also the code above using stackalloc NODE[1] just feels wrong and as
>> > >> if I'm using it to do something it wasn't intended to do. Now for the
>> > >> application it is important to keep the spirit of a linked list and
>> > >> not an stacked list, meaning I want to be able to move the links
>> > >> around dynamically.
>> >
>> > >> How can I do this correctly, I may not be understanding the
>> > >> fundamentals of C# (such as how variables are treated). Also NODE is
>> a
>> > >> struct, which is different from a Class in C# in terms of data from
>> my
>> > >> understanding.
>> >
>> > >> Appreciate your help.
>> >
>>  > >> -Alon- Hide quoted text -
>> >
>> > - Show quoted text -
>>
>
>
>
> --
> Charles A. Lopez
> [email protected]
>
> Bachelor of Arts - Computer Science
> New York University
>
> Registered Microsoft Partner
>
> New York City, NY
>

Reply via email to