Memory could not be "Read"-still
| Cbas (11) | |||
| I have a function which i run three times. Its called float* departments(int a,float b, float c[], float d) and returns a 320 array It runs perfectly twice, but on the third time window's gives me the error message: The instruction at "0x7c93426d" reference memory at "0xc2940f10". The memory could not be "read" <Ok> to terminate, <cancel> to debug I have no idea what is causing this crash,its obviously a memory thing(i think) but how do i fix it? | |||
| Duoas (1087) | |||
| You are trying to write or read memory that doesn't belong to you. Look for anyplace that you can access memory outside the proper bounds. (If you can't see it, post your code.) | |||
| Cbas (11) | |||
| How do i access memory outside the proper bounds? I could post the the code, but its pretty long?? Thanks Duoas,by the way
| |||
| Duoas (1087) | |||
You cannot return a static array. Eg:
The reason is that result[] ceases to exist when the function terminates, and ptr points to memory you do not own. The fact that it worked a couple of times is pure luck. | |||
| Cbas (11) | |||
| Thank you again... But how do i return an array then?? | |||
| Zaita (933) | |||
| |||
| Cbas (11) | |||
| THANK YOU THANK YOU Just one more thing. My function, as well as returning an array, also outputs a file-the file name is specified by user. The fucntion also runs three times, with the the option of running more if the user is not satisfied
The program loops, so the CSV file eventually has about 320 entries in three colums The problem is, on about the 2nd loop(the 4th CSV created) The memory error occures. I Find if i delete any files in my working folder it seems to run maybe 3 times before i get the "Windows has encountered an error and has to end the program" Any ideas why?? Thank you! | |||
| jsmith (187) | |||
| Three possible problems. 1) To free the memory, you should do
delete [] run1; // without the asterisk 2) Line 24 is deleting run2 a second time. I think you meant run3. 3) Index [10] of the arrays is outside the bounds of the arrays. Since you do new float[10], the valid indices range from 0...9. | |||
This topic is archived - New replies not allowed.
