Re: Can't assign value to structure in array?
- From: "Frank Hileman" <frankhil@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 8 Jun 2005 12:37:07 -0700
We were talking about structs in arrays. Those would always be on the heap,
not the stack. If you are talking about a value type used as a parameter or
local variable, or a temporary returned by an operator overload, then you
are potentially looking at the stack.
The stack is allocated according to the number and size of parameters, local
variables, and temporaries used by a method. When the method returns the
stack space is immediately released and reused for the next method call.
Basically it is just a preallocated block of memory with the current offset
kept in a register than is incremented and decremented. Often temporaries,
local variables, and parameters wind up in registers instead, and take no
space on the stack. This is the ideal situation.
The .NET GC is fast. But it can never beat the memory size and speed of
value types in local variables or parameters, as they may be in registers.
Even if they are on the stack, the .net heap allocater continues to move
into new memory addresses as it allocates new objects, until a GC is
triggered, whereas the stack constantly reuses a smaller area of memory, so
you get better locality of reference. The .NET allocator and GC are so fast
sometimes the heap seems similar to a stack over a larger span of memory.
Look at the timeline view in the CLRProfiler tool.
Regards,
Frank Hileman
"Brett" <no@xxxxxxxx> wrote in message
news:OzwKpxFbFHA.3048@xxxxxxxxxxxxxxxxxxxxxxx
> The object is stored on the heap and GC takes place there. Is the struct
> stored on the stack? I'd assume it is since it is value type. Also, how
> is the stack cleared? By GC?
>
> Thanks,
> Brett
.
- References:
- Can't assign value to structure in array?
- From: Brett
- Re: Can't assign value to structure in array?
- From: Jon Skeet [C# MVP]
- Re: Can't assign value to structure in array?
- From: Bruce Wood
- Re: Can't assign value to structure in array?
- From: Frank Hileman
- Re: Can't assign value to structure in array?
- From: Jonathan Allen
- Re: Can't assign value to structure in array?
- From: Frank Hileman
- Re: Can't assign value to structure in array?
- From: Jonathan Allen
- Re: Can't assign value to structure in array?
- From: Frank Hileman
- Re: Can't assign value to structure in array?
- From: Brett
- Can't assign value to structure in array?
- Prev by Date: Re: Can't assign value to structure in array?
- Next by Date: Re: .Net security for shared network driver
- Previous by thread: Re: Can't assign value to structure in array?
- Next by thread: Re: Can't assign value to structure in array?
- Index(es):
Relevant Pages
|