Archived

This topic is now archived and is closed to further replies.

Problems with new operator initializing array?

This topic is 4944 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I have no idea what''s causing a 0xC000005 Access Violation here, help greatly appreciated: dataptr = new MyRGB[x*y]; dataptr is of type MyRGB * and is defined as a public member of a class. Code shown above is in one of the class''s member functions. It also maybe important to note that when this occurs, my values of x and y are 256 and 192. STRUCT MyRGB should only take up around 3 bytes, so the total space being allocated is only 144 KB. This shouldn''t be a problem with not having enough memory. dataptr is supposedly initialized as a NULL pointer in the class''s constructor btw. Thanks for looking at this.

Share this post


Link to post
Share on other sites
I can''t understand why it should be any problem since it sound completely correct. Are you able to post some more code that I can look at?

- Patrik Willbo

The Lord says He can get me out of this mess, but He''s pretty sure you''re fucked.
- Stephen (Braveheart)

Share this post


Link to post
Share on other sites
Another thing i noticed is that dataptr can''t seem to be modified at all. If i do dataptr = 0 in any place but the class''s constructor, another 0xC0000005 error happens. Maybe this''ll be useful information.

Share this post


Link to post
Share on other sites
Try making the size smaller, say 1KB, and then try allocating, then see if there's an exception. Maybe the amount of memory is a problem, but your compiler should be able to make sure you have enough...

edit: useful info may be: without changing segments, your program should be able to address 4MB (2^32 - 1, exactly), so how big is your program? Are you doing anything outside of protected mode? Or are you doing some real mode flat model programming?

[edited by - temp_ie_cant_thinkof_name on May 30, 2004 2:35:49 PM]

Share this post


Link to post
Share on other sites
thanks everyone, I think i''ve figured out why it wasn''t working... dataptr was a pointer in a pointer to an object. the pointer had not been initialized...so therefore the access violation. Thanks to all of you who replied.

Share this post


Link to post
Share on other sites