R
Robert Bouillon
I have a StackOverflowException that's NOT caused by a recursive function.
I'm having a hard time with this exception as it takes about an hour to
reproduce, and I'm not sure what's causing it.
I have a serial stream class that reads bytes from a serial port. The
information is stored in a local byte array of about 4k. When I'm done
processing the data, the byte array is assigned to an object property that
serves to retain a record of the bytes transferred. I think this may be the
problem.
I know that locally declared byte arrays are stored on the stack. Am I
mistaken in thinking that assigning a byte array to an object property boxes
the array (Because the object exists on the heap)? If so, then this is my
problem. How do I box the array while keeping it strong-typed?
If assigning a byte array to a class property (on the same thread) DOES box
the array, then I'm at a loss to the problem. Are there any tips or tricks
to determining what exactly is being stored on the stack?
Of course because error handling requires stack space, and my stack is
invalid due to an overflow, it's very difficult trying to track down this
bug.
EXAMPLE CODE (Short version: not actual code. Just to demonstrate how my
code handles the array):
do{
byte[] buffer = new byte[4196];
p_Stream.Read(buffer,0,4196);
DoStuff(buffer);
DataRecord dr = new DataRecord();
dr.Data = buffer;
} while(i++<500)
Thanks
--ROBERT
I'm having a hard time with this exception as it takes about an hour to
reproduce, and I'm not sure what's causing it.
I have a serial stream class that reads bytes from a serial port. The
information is stored in a local byte array of about 4k. When I'm done
processing the data, the byte array is assigned to an object property that
serves to retain a record of the bytes transferred. I think this may be the
problem.
I know that locally declared byte arrays are stored on the stack. Am I
mistaken in thinking that assigning a byte array to an object property boxes
the array (Because the object exists on the heap)? If so, then this is my
problem. How do I box the array while keeping it strong-typed?
If assigning a byte array to a class property (on the same thread) DOES box
the array, then I'm at a loss to the problem. Are there any tips or tricks
to determining what exactly is being stored on the stack?
Of course because error handling requires stack space, and my stack is
invalid due to an overflow, it's very difficult trying to track down this
bug.
EXAMPLE CODE (Short version: not actual code. Just to demonstrate how my
code handles the array):
do{
byte[] buffer = new byte[4196];
p_Stream.Read(buffer,0,4196);
DoStuff(buffer);
DataRecord dr = new DataRecord();
dr.Data = buffer;
} while(i++<500)
Thanks
--ROBERT