0xc0000005 error

This is a discussion on 0xc0000005 error within the C++ Programming forums, part of the General Programming Boards category; These are interesting. I mean of course I did insert new variables, and assigned some functions as well. But I ...

  1. #16
    Registered User
    Join Date
    Mar 2003
    Posts
    105
    These are interesting.
    I mean of course I did insert new variables, and assigned some functions as well. But I use static arrays, and this makes such overflows (as far as I know) impossible, as if I try to write to them I'd run into exceptions upon programming, not only upon execution (since nothing changes, but in one case I compile&run&debug, and in the other I just run the exe).
    Is there anything in C builder which would make these kind of errors traceable during development? Is there a way I can monitor the memory usage of my program? I didn't really need to use advanced C builder features until now...

  2. #17
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I wouldn't trust the compiler to always [or even often] detect out-of-bounds array accesses. The C language doesn't do that very well, and whilst the latest MS products do have some extensions to make an attempt, it's quite possible that you can get these things wrong and still execute for quite some time.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #18
    Registered User
    Join Date
    Jun 2005
    Posts
    6,529
    There is certainly nothing special about how BCB handles static arrays that allows any assurance that out-of-bound accesses will be detected, let alone generate exceptions. If you're assuming that, you're wrong. And it explains why you're having trouble: if you assume your code won't cause problems because it uses static arrays, you virtually guarantee you won't find any problems it causes.

    The problem with out-of-bounds array accesses (or other forms of pointer molestation) is that there is no single effect, so there is no guaranteed way to detect them. The preferred approach is to prevent them in the first case: which, clearly, is a bit late for you.

  4. #19
    Registered User
    Join Date
    Mar 2003
    Posts
    105
    Okay. But how should I prevent these causes? I use static arrays, which take less than 1 Megs of memory in total. The ony way I access these arrays is that I load and read them in certain cycles. The only occasion I run through the whole array is at the start, when I clear them.

    So even if I accept that not all of the out of bounds accesses are not detected, what can I do against it? When I'm saying that "I use static arrays", I also say, that I monitor their use to avoid out of bound access (in my cycles when I load or read them).

    Is it possible by the way that I use too complex structures, or too big arrays?

    (BTW: I began rewriting the codes, and I nearly finished, but I didn't run into any the problem.)

  5. #20
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Well, it's certain the problem you are seeing is caused by a bad memory access - it is impossible to say without access to the source [and a failing test-setup] to say what the actual problem is.

    Edit: That was probably a bit brief. You need to write code defensively, checking all indexes to ALL arrays, all over the code. And there is obviously a possibility that your library that you use is broken in some way.

    Can you run a debugger and catch the actual error and get a stack-trace of where it is when it falls over?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #21
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,157
    When you say static arrays, you mean arrays in contrast with dynamically allocated arrays, right?

    It seems to me that you could use the at() member function of the fixed size std::tr1::array class template or std::vector.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #22
    Registered User
    Join Date
    Mar 2003
    Posts
    105
    matsp: that's what I'm doing... I'm working with a few data, with huge arrays for it (so most of the array elements are actually empty), and when sweeping through the whole array, I check for the end index.
    How do I get a copy of the stack trace in BCB?

    The library I use, and it gets bad is the vcl50.bpl. That's practically a basic library, isn't it? So it shouldn't do anything wrong. Or is it possible, that I have modified it some way, I inserted something into it?

    laserlight: yes, the contrast was right. I allocate them staticly. I don't really think I use the at() function. Maybe something similar. What does "at()" do BTW?

  8. #23
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,157
    Maybe something similar. What does "at()" do BTW?
    Throw a std::out_of_range exception if the index passed is invalid.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #24
    Registered User
    Join Date
    Mar 2003
    Posts
    105
    Can you give me a sample code?

  10. #25
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    vector<int> array(10);
    
    for(i = 0; i < 11; i++)
       array.at(i) = i;
    This will throw the exception when i is 10.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #26
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,157
    Can you give me a sample code?
    A really basic compilable example would be:
    Code:
    #include <iostream>
    #include <vector>
    #include <stdexcept>
    
    int main()
    {
        std::vector<int> numbers;
        try
        {
            std::cout << numbers.at(0) << std::endl;
        }
        catch (const std::out_of_range& e)
        {
            std::cout << e.what() << std::endl;
        }
    }
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #27
    Registered User
    Join Date
    Mar 2003
    Posts
    105
    Thx

    BCB used to give me execeptions when I produce such overflows without at(). But I'll insert something like this into the loops, and see what happens.

  13. #28
    Registered User
    Join Date
    Mar 2003
    Posts
    105
    One more thing I noticed is that I use several string arrays. Can they cause problems? (Even though the array is static, but the memory being used by many many string may be quite big.)

  14. #29
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Hankyaku View Post
    One more thing I noticed is that I use several string arrays. Can they cause problems? (Even though the array is static, but the memory being used by many many string may be quite big.)
    If the string itself is a char array or char pointer, then it's certainly a potential candidate. If it's using std::string class, then it should be OK.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  15. #30
    Registered User
    Join Date
    Mar 2003
    Posts
    105
    Since I use C++Builder 5.0 I use AnsiString types.
    And the real thing I'm wondering on is that since now, I never had any problems with the code I wrote, I mean the exceptions or overflows. Whenever a problem arouse, the compiler always told me that there's a problem, or during debug they appeared. A clear nice crash, at a definite place. But now? These programs are less complex than those I wrote earlier. Still, it's a mess now. One of them actually is just refreshing an older code, and making some additions. I'm having a similar problem at that one. (That's why I was thinking that a new installed component could've caused the trouble.)

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 10:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 02:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21