Problems Allocating Simple Array - NullReferenceException 
Author Message
 Problems Allocating Simple Array - NullReferenceException

Hi, I've just come across a really odd problem in a managed app.  To narrow
the problem down, I've got a simple line that I'm using as a test :

char* pb = new char[11753];

Depending on where in my program I put this line.....it may work or it may
give me an error.  The error I'm getting is:

Unhandled Exception: System.NullReferenceException: Object reference not set
to an instance of an object.

My question is:  Why would this error only happen in certain areas of my
program?  You'd think if the line works at the beginning, it should also
work if I move it to the end?

Help....
/\/\ark



Tue, 06 Dec 2005 02:27:03 GMT  
 Problems Allocating Simple Array - NullReferenceException
"char *pb = new char[11753];" creates a __nogc pointer to
an unmanaged array. Is this what you wanted to do?

Quote:
>-----Original Message-----
>Hi, I've just come across a really odd problem in a

managed app.  To narrow
Quote:
>the problem down, I've got a simple line that I'm using
as a test :

>char* pb = new char[11753];

>Depending on where in my program I put this line.....it
may work or it may
>give me an error.  The error I'm getting is:

>Unhandled Exception: System.NullReferenceException:

Object reference not set
Quote:
>to an instance of an object.

>My question is:  Why would this error only happen in
certain areas of my
>program?  You'd think if the line works at the beginning,
it should also
>work if I move it to the end?

>Help....
>/\/\ark

>.



Tue, 06 Dec 2005 03:50:35 GMT  
 Problems Allocating Simple Array - NullReferenceException
If you are trying to create a managed array, do this:

char pb __gc[] = new char __gc[11753];

       or

System::Char pb[] = new System::Char[11753];

Quote:
>-----Original Message-----
>Hi, I've just come across a really odd problem in a

managed app.  To narrow
Quote:
>the problem down, I've got a simple line that I'm using
as a test :

>char* pb = new char[11753];

>Depending on where in my program I put this line.....it
may work or it may
>give me an error.  The error I'm getting is:

>Unhandled Exception: System.NullReferenceException:

Object reference not set
Quote:
>to an instance of an object.

>My question is:  Why would this error only happen in
certain areas of my
>program?  You'd think if the line works at the beginning,
it should also
>work if I move it to the end?

>Help....
>/\/\ark

>.



Tue, 06 Dec 2005 04:00:00 GMT  
 Problems Allocating Simple Array - NullReferenceException
Yes, that's what I was trying to do.....create an unmanaged array.

/\/\ark



Quote:
> "char *pb = new char[11753];" creates a __nogc pointer to
> an unmanaged array. Is this what you wanted to do?

> >-----Original Message-----
> >Hi, I've just come across a really odd problem in a
> managed app.  To narrow
> >the problem down, I've got a simple line that I'm using
> as a test :

> >char* pb = new char[11753];

> >Depending on where in my program I put this line.....it
> may work or it may
> >give me an error.  The error I'm getting is:

> >Unhandled Exception: System.NullReferenceException:
> Object reference not set
> >to an instance of an object.

> >My question is:  Why would this error only happen in
> certain areas of my
> >program?  You'd think if the line works at the beginning,
> it should also
> >work if I move it to the end?

> >Help....
> >/\/\ark

> >.



Tue, 06 Dec 2005 05:02:52 GMT  
 Problems Allocating Simple Array - NullReferenceException
You need to provide an example of what you are talking
about.

Quote:
>-----Original Message-----
>Yes, that's what I was trying to do.....create an
unmanaged array.

>/\/\ark



>> "char *pb = new char[11753];" creates a __nogc pointer
to
>> an unmanaged array. Is this what you wanted to do?

>> >-----Original Message-----
>> >Hi, I've just come across a really odd problem in a
>> managed app.  To narrow
>> >the problem down, I've got a simple line that I'm using
>> as a test :

>> >char* pb = new char[11753];

>> >Depending on where in my program I put this line.....it
>> may work or it may
>> >give me an error.  The error I'm getting is:

>> >Unhandled Exception: System.NullReferenceException:
>> Object reference not set
>> >to an instance of an object.

>> >My question is:  Why would this error only happen in
>> certain areas of my
>> >program?  You'd think if the line works at the
beginning,
>> it should also
>> >work if I move it to the end?

>> >Help....
>> >/\/\ark

>> >.

>.



Tue, 06 Dec 2005 10:32:21 GMT  
 Problems Allocating Simple Array - NullReferenceException
Hi, thanks, I managed to figure it out.  It really threw me for a loop
because the call sometimes worked and other times generated the error that I
posted.  I started with the command at the beginning of my program and it
worked fine.  I kept moving it forward until it finally failed inside on of
my classes.  I figured it had to be something stupid.....I had an unmanaged
array, completely unrelated to my test command, and I was writing past the
end of the array.  I guess I was writing over something that was then
causing this char definition to fail.  Pretty strange.

Thanks,
/\/\ark



Quote:
> You need to provide an example of what you are talking
> about.

> >-----Original Message-----
> >Yes, that's what I was trying to do.....create an
> unmanaged array.

> >/\/\ark



> >> "char *pb = new char[11753];" creates a __nogc pointer
> to
> >> an unmanaged array. Is this what you wanted to do?

> >> >-----Original Message-----
> >> >Hi, I've just come across a really odd problem in a
> >> managed app.  To narrow
> >> >the problem down, I've got a simple line that I'm using
> >> as a test :

> >> >char* pb = new char[11753];

> >> >Depending on where in my program I put this line.....it
> >> may work or it may
> >> >give me an error.  The error I'm getting is:

> >> >Unhandled Exception: System.NullReferenceException:
> >> Object reference not set
> >> >to an instance of an object.

> >> >My question is:  Why would this error only happen in
> >> certain areas of my
> >> >program?  You'd think if the line works at the
> beginning,
> >> it should also
> >> >work if I move it to the end?

> >> >Help....
> >> >/\/\ark

> >> >.

> >.



Sat, 10 Dec 2005 05:05:38 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Simple System.NullReferenceException question

2. problem with allocating multidimensional array

3. Dynamically allocated array problem

4. problem allocating/freeing memory of multidimensional arrays

5. strcmp and dynamicly allocated array problem

6. Problem De-allocating Memory in variable sized arrays

7. Allocating a array of char arrays???

8. dynamically allocating an array of array of...

9. Simple Array problem in MC++

10. simple array loop problem

11. Simple array passing problem

12. Simple array Problem

 

 
Powered by phpBB® Forum Software