Problems with new operator initializing array?
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.
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)
- 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.
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]
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]
If you''re getting an error when assigning a value to dataptr, it sounds like you have stack corruption...
Supposing I do have a stack corruption...what are possible causes of it and how can they be corrected? Thanks.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement