Problems with new operator initializing array?

Started by
6 comments, last by arkmaster 19 years, 10 months ago
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.
Advertisement
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)
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.
You need to learn how to use the debugger. Debgging code without using a debugger is like fixing a car without opening the hood.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
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]
"I study differential and integral calculus in my spare time." -- Karl Marx
If you''re getting an error when assigning a value to dataptr, it sounds like you have stack corruption...

---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.

Supposing I do have a stack corruption...what are possible causes of it and how can they be corrected? Thanks.
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.

This topic is closed to new replies.

Advertisement