Re: How do you store a stoopid array in the stoopid ViewState?
- From: Brian Delahunty <BrianDelahunty@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 10 Aug 2005 16:47:01 -0700
To be honest I can't see where there is a problem. The code looks fine....
the error is saying you are trying to add 1 to an object, which would be an
error, but I can't see where it is happening and the code I tested (the one I
posted in my inital response) works fine... I have it in a code behind
file... however, even if you have it inline it should still work.
If line 128 is giving you the error, i.e. "int_array[nn] = int_array[nn] +
1;" then the only thing I can think of is that int_array[nn] is actually
returning an object instead of a UInt32... I can't see why this would be the
case but it seems like it is... so, you could try this changing that line to:
int_array[nn] = ((UInt32) int_array[nn]) + 1;
and if that doesn't work you could try this
int_array[nn] = UInt32.Parse(int_array[nn].ToString()) + 1;
Anyway, seems like you are having a weird problem. As regards your question
about arrays. Unfortunately .NET arrays, even array of value types, are
stored on the heap. The only thing stored on the stack is a reference to the
array. I don't know if there is a way around this. I doubt it. By the way, do
you mind if I ask why you want it on the stack? Is it just for performance
reasons?
I hope I've helped somehow.
Brian Delahunty
Ireland
http://briandela.com/blog
"wASP" wrote:
> On Wed, 10 Aug 2005 14:38:05 -0700, Brian Delahunty
> <BrianDelahunty@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Hi Brian,
>
> I have a problem with the ELSE case:
>
> /* ------------------------------------------------------------------ */
> /* ------------------------------------------------------------------ */
> else
> {
> Label1.Text = " On postback: |";
>
> UInt32[] int_array = (UInt32[]) ViewState["int_array"];
>
> for (UInt32 nn = 0; nn < 11; nn++)
> int_array[nn] += 1;
>
> for (UInt32 nn = 0; nn < 11; nn++)
> Label1.Text = Label1.Text + int_array[nn].ToString() + "|";
> }
> }
> /* ------------------------------------------------------------------ */
> /* ------------------------------------------------------------------ */
>
>
>
> It threw the following exception:
> /* ------------------------------------------------------------------ */
> /* ------------------------------------------------------------------ */
>
> Server Error in '/Webfolder01' Application.
> --------------------------------------------------------------------------------
>
> Compilation Error
> Description: An error occurred during the compilation of a resource required
> to service this request. Please review the following specific error details
> and modify your source code appropriately.
>
> Compiler Error Message: CS0019: Operator '+' cannot be applied to
> operands of type 'object' and 'int'
>
> Source Error:
>
> Line 127: for (Int32 nn = 0; nn < 11; nn++)
> Line 128: int_array[nn] = int_array[nn] + 1;
> Line 129:
> Line 130: for (Int32 nn = 0; nn < 11; nn++)
>
> /* ------------------------------------------------------------------ */
> /* ------------------------------------------------------------------ */
>
>
>
> Do I need to set some kind of a switch or something somewhere?
>
>
> >Also, what do you mean by "immediate array"?
>
> One that allocates a block of memory from the program stack,
> instead of dynamically from the heap.
>
> IOW, C# creates arrays dynamically - much like doing the following in C++:
>
> int (*int_array)[] = farmalloc (11);
>
>
> ... instead of allocating from the program stack in C++ like this:
>
> int int_array[11];
>
> I don't see anything in any docs on C# that will let you do anything
> other than to allocate array-space from the heap.
>
>
> - wASP
>
.
- Follow-Ups:
- References:
- How do you store a stoopid array in the stoopid ViewState?
- From: wASP
- RE: How do you store a stoopid array in the stoopid ViewState?
- From: Brian Delahunty
- Re: How do you store a stoopid array in the stoopid ViewState?
- From: wASP
- How do you store a stoopid array in the stoopid ViewState?
- Prev by Date: RE: Should I explicitly initialize all member variables?
- Next by Date: RE: Should I explicitly initialize all member variables?
- Previous by thread: Re: How do you store a stoopid array in the stoopid ViewState?
- Next by thread: Re: How do you store a stoopid array in the stoopid ViewState?
- Index(es):
Relevant Pages
|