Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Invalid parameter passed to C runtime function

Invalid parameter passed to C runtime function

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtcreatorqstringlistruntime error
19 Posts 3 Posters 10.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lasith
    wrote on last edited by
    #1

    When I run my code of my Qt C++ application I get the following error! What can be the main reasons for such an error?
    "Invalid parameter passed to C runtime function.
    terminate called after throwing an instance of 'std::bad_alloc'
    what(): std::bad_alloc"

    JonBJ 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Lasith said in Invalid parameter passed to C runtime function:

      std::bad_alloc

      That is normally when you run out of memory :)

      Check the mem use of your app.

      L 1 Reply Last reply
      1
      • L Lasith

        When I run my code of my Qt C++ application I get the following error! What can be the main reasons for such an error?
        "Invalid parameter passed to C runtime function.
        terminate called after throwing an instance of 'std::bad_alloc'
        what(): std::bad_alloc"

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @Lasith
        Check your calls to "std::alloc", i.e. everywhere you allocate memory. If you do inadvertently do something which boils down to, say:

        size_t size = (size_t) -1;
        std::alloc(size);
        

        then you will have memory problems :)

        L 1 Reply Last reply
        0
        • mrjjM mrjj

          @Lasith said in Invalid parameter passed to C runtime function:

          std::bad_alloc

          That is normally when you run out of memory :)

          Check the mem use of your app.

          L Offline
          L Offline
          Lasith
          wrote on last edited by
          #4

          @mrjj You mean Hard disk or main memory?

          mrjjM 1 Reply Last reply
          0
          • L Lasith

            @mrjj You mean Hard disk or main memory?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Lasith

            Main memory.
            the new function can trow that error if you try to allocate and there is not enough free.

            http://en.cppreference.com/w/cpp/memory/new/bad_alloc

            L 1 Reply Last reply
            1
            • JonBJ JonB

              @Lasith
              Check your calls to "std::alloc", i.e. everywhere you allocate memory. If you do inadvertently do something which boils down to, say:

              size_t size = (size_t) -1;
              std::alloc(size);
              

              then you will have memory problems :)

              L Offline
              L Offline
              Lasith
              wrote on last edited by
              #6

              @JNBarchan I already have this issue :O

              1 Reply Last reply
              0
              • mrjjM mrjj

                @Lasith

                Main memory.
                the new function can trow that error if you try to allocate and there is not enough free.

                http://en.cppreference.com/w/cpp/memory/new/bad_alloc

                L Offline
                L Offline
                Lasith
                wrote on last edited by
                #7

                @mrjj so how can I increase the amount of memory?

                mrjjM 1 Reply Last reply
                0
                • L Lasith

                  @mrjj so how can I increase the amount of memory?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #8

                  @Lasith
                  Add more memory to the pc.
                  But how much does the target currently have ?
                  Did you check the how much app uses etc?

                  Or find out if you are leaking memory and hence it runs dry.
                  You have to find out what causes it using the debugger.
                  Step through the code to find out where or in what context the
                  error comes.

                  You have not shown any code so its not possible to guess at.

                  L 1 Reply Last reply
                  3
                  • mrjjM mrjj

                    @Lasith
                    Add more memory to the pc.
                    But how much does the target currently have ?
                    Did you check the how much app uses etc?

                    Or find out if you are leaking memory and hence it runs dry.
                    You have to find out what causes it using the debugger.
                    Step through the code to find out where or in what context the
                    error comes.

                    You have not shown any code so its not possible to guess at.

                    L Offline
                    L Offline
                    Lasith
                    wrote on last edited by
                    #9

                    @mrjj Thanx how can I check the current memory usage? Using the task manager?

                    mrjjM 1 Reply Last reply
                    0
                    • L Lasith

                      @mrjj Thanx how can I check the current memory usage? Using the task manager?

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Lasith
                      Yes it can give a good hint. Start app and see how much it uses.

                      there is also
                      https://docs.microsoft.com/en-us/sysinternals/downloads/rammap

                      1 Reply Last reply
                      0
                      • mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        Does error comes as soon as you start the app or
                        does it take some time?

                        L 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          Does error comes as soon as you start the app or
                          does it take some time?

                          L Offline
                          L Offline
                          Lasith
                          wrote on last edited by Lasith
                          #12

                          @mrjj The error oocurs when I click a button which feeds a set of values to a QStringList through 2 for loops!

                          mrjjM JonBJ 2 Replies Last reply
                          0
                          • L Lasith

                            @mrjj The error oocurs when I click a button which feeds a set of values to a QStringList through 2 for loops!

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @Lasith
                            Ok, you might copy a lot around and run out of memory.
                            is it 32/64 bit app?
                            how much memory do you have?

                            L 1 Reply Last reply
                            0
                            • mrjjM mrjj

                              @Lasith
                              Ok, you might copy a lot around and run out of memory.
                              is it 32/64 bit app?
                              how much memory do you have?

                              L Offline
                              L Offline
                              Lasith
                              wrote on last edited by
                              #14

                              @mrjj I can not check now :( Its in my office PC Now I am home I will notify you tomorrow! :)

                              mrjjM 1 Reply Last reply
                              0
                              • L Lasith

                                @mrjj I can not check now :( Its in my office PC Now I am home I will notify you tomorrow! :)

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                @Lasith
                                Ok, if you copy lists, it might be the reason.
                                You should show the code.
                                Using all mem with strings, takes a lot of strings :)

                                1 Reply Last reply
                                0
                                • L Lasith

                                  @mrjj The error oocurs when I click a button which feeds a set of values to a QStringList through 2 for loops!

                                  JonBJ Offline
                                  JonBJ Offline
                                  JonB
                                  wrote on last edited by
                                  #16

                                  @Lasith said in Invalid parameter passed to C runtime function:

                                  @mrjj The error oocurs when I click a button which feeds a set of values to a QStringList through 2 for loops!

                                  And you're sure those 2 loops aren't actually unlimited? ;-) Better look at how many iterations they do :) You do have to do really quite a lot of iterations to run out of memory!

                                  L 1 Reply Last reply
                                  1
                                  • JonBJ JonB

                                    @Lasith said in Invalid parameter passed to C runtime function:

                                    @mrjj The error oocurs when I click a button which feeds a set of values to a QStringList through 2 for loops!

                                    And you're sure those 2 loops aren't actually unlimited? ;-) Better look at how many iterations they do :) You do have to do really quite a lot of iterations to run out of memory!

                                    L Offline
                                    L Offline
                                    Lasith
                                    wrote on last edited by Lasith
                                    #17

                                    @JNBarchan No the upper limits of the conditions is finite! Any way I will check and see! Plus if its an infinite loop the error message is different as I remember!

                                    JonBJ 1 Reply Last reply
                                    0
                                    • L Lasith

                                      @JNBarchan No the upper limits of the conditions is finite! Any way I will check and see! Plus if its an infinite loop the error message is different as I remember!

                                      JonBJ Offline
                                      JonBJ Offline
                                      JonB
                                      wrote on last edited by JonB
                                      #18

                                      @Lasith said in Invalid parameter passed to C runtime function:

                                      @JNBarchan No the upper limits of the conditions is finite!

                                      This is good to know. But there are finite numbers and then there are other finite numbers. Numbers like, say, 0x7FFFFFFF (2 billion?) as the limit in each loop (I'm understanding they are nested?) will cause a lot of iterations... ;-)

                                      L 1 Reply Last reply
                                      1
                                      • JonBJ JonB

                                        @Lasith said in Invalid parameter passed to C runtime function:

                                        @JNBarchan No the upper limits of the conditions is finite!

                                        This is good to know. But there are finite numbers and then there are other finite numbers. Numbers like, say, 0x7FFFFFFF (2 billion?) as the limit in each loop (I'm understanding they are nested?) will cause a lot of iterations... ;-)

                                        L Offline
                                        L Offline
                                        Lasith
                                        wrote on last edited by
                                        #19

                                        @JNBarchan yeah they are nested for loops!

                                        1 Reply Last reply
                                        0

                                        • Login

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • Users
                                        • Groups
                                        • Search
                                        • Get Qt Extensions
                                        • Unsolved