Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CString max character length

CString max character length

Scheduled Pinned Locked Moved C / C++ / MFC
question
11 Posts 7 Posters 0 Views 1 Watching
  • 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.
  • G Offline
    G Offline
    GDavy
    wrote on last edited by
    #1

    hello, I remember reading once that a CString object has a maximum amount of characters it can hold, I just can't seem to find how much that is. Does anybody know how much that count is? If you have a URL with that info that would also be neat. Greetings, Davy

    T M K H 4 Replies Last reply
    0
    • G GDavy

      hello, I remember reading once that a CString object has a maximum amount of characters it can hold, I just can't seem to find how much that is. Does anybody know how much that count is? If you have a URL with that info that would also be neat. Greetings, Davy

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      sure, check it's index type... you'll figure out how far it can go (so, how many TCHARs a CString can hold)


      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

      1 Reply Last reply
      0
      • G GDavy

        hello, I remember reading once that a CString object has a maximum amount of characters it can hold, I just can't seem to find how much that is. Does anybody know how much that count is? If you have a URL with that info that would also be neat. Greetings, Davy

        M Offline
        M Offline
        Matthew Faithfull
        wrote on last edited by
        #3

        From memory 32767. Two things to note- The best way to confirm this is to look at the CString source. The other thing that doing this will confirm for you is that if you're going anywhere near needing to know what the limit is you shouldn't be using CStrings. A preallocated 32K or 64K character buffer will likely be serveral times faster, depending on what you're doing with it of course, and the Win32 API and MSVCRT have a vast array of string functions that operate directly on character arrays. Good luck.

        Nothing is exactly what it seems but everything with seems can be unpicked.

        T G D 3 Replies Last reply
        0
        • G GDavy

          hello, I remember reading once that a CString object has a maximum amount of characters it can hold, I just can't seem to find how much that is. Does anybody know how much that count is? If you have a URL with that info that would also be neat. Greetings, Davy

          K Offline
          K Offline
          KarstenK
          wrote on last edited by
          #4

          because of implementation: MAX_INT - 1 = 2^32 - 1

          Greetings from Germany

          1 Reply Last reply
          0
          • M Matthew Faithfull

            From memory 32767. Two things to note- The best way to confirm this is to look at the CString source. The other thing that doing this will confirm for you is that if you're going anywhere near needing to know what the limit is you shouldn't be using CStrings. A preallocated 32K or 64K character buffer will likely be serveral times faster, depending on what you're doing with it of course, and the Win32 API and MSVCRT have a vast array of string functions that operate directly on character arrays. Good luck.

            Nothing is exactly what it seems but everything with seems can be unpicked.

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #5

            are you sticking to Windows 3.1 with MFC 3 ?? :~ and suggest to use std::string rather than allocating a 32K buffer ! WTF !!!


            [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

            M 1 Reply Last reply
            0
            • M Matthew Faithfull

              From memory 32767. Two things to note- The best way to confirm this is to look at the CString source. The other thing that doing this will confirm for you is that if you're going anywhere near needing to know what the limit is you shouldn't be using CStrings. A preallocated 32K or 64K character buffer will likely be serveral times faster, depending on what you're doing with it of course, and the Win32 API and MSVCRT have a vast array of string functions that operate directly on character arrays. Good luck.

              Nothing is exactly what it seems but everything with seems can be unpicked.

              G Offline
              G Offline
              GDavy
              wrote on last edited by
              #6

              Thanks for the reply. The required space is luckily not really near the 32K. It's just that I have a bug with some rather big strings 9+K not passing over a socket connection and I just wanted to make sure that the CString was not the cause of it. Greetings, Davy

              M 1 Reply Last reply
              0
              • T toxcct

                are you sticking to Windows 3.1 with MFC 3 ?? :~ and suggest to use std::string rather than allocating a 32K buffer ! WTF !!!


                [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                M Offline
                M Offline
                Matthew Faithfull
                wrote on last edited by
                #7

                std::string is fine if you don't care how the code you're using works. To most developers it's still unreadable gibberish with inadequate usage documentation of precisely the 'how much can it hold' type that the OP is interested in. I code on everything from Windows 3.11 to Vista and on CE in what is still, essentially, MFC 3, have written my own replacement CString class and have written a commercial inline parser generator which uses preallocated 64K text buffers, simple, reliable, consistent, fast and easy to understand. So yes if someone is struggling with determining a size limit from the CString code and dealing with 32K+ lumps of text data then I think simple buffers are good advice. KISS was the first and last thing my C++ lecturers ever taught me.:)

                Nothing is exactly what it seems but everything with seems can be unpicked.

                1 Reply Last reply
                0
                • M Matthew Faithfull

                  From memory 32767. Two things to note- The best way to confirm this is to look at the CString source. The other thing that doing this will confirm for you is that if you're going anywhere near needing to know what the limit is you shouldn't be using CStrings. A preallocated 32K or 64K character buffer will likely be serveral times faster, depending on what you're doing with it of course, and the Win32 API and MSVCRT have a vast array of string functions that operate directly on character arrays. Good luck.

                  Nothing is exactly what it seems but everything with seems can be unpicked.

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  Matthew Faithfull wrote:

                  From memory 32767.

                  Sounds like you need a memory update.


                  "A good athlete is the result of a good and worthy opponent." - David Crow

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  M 1 Reply Last reply
                  0
                  • D David Crow

                    Matthew Faithfull wrote:

                    From memory 32767.

                    Sounds like you need a memory update.


                    "A good athlete is the result of a good and worthy opponent." - David Crow

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    M Offline
                    M Offline
                    Matthew Faithfull
                    wrote on last edited by
                    #9

                    My 250TB is just fine. If only I could find the runtime to re-index it:)

                    Nothing is exactly what it seems but everything with seems can be unpicked.

                    1 Reply Last reply
                    0
                    • G GDavy

                      Thanks for the reply. The required space is luckily not really near the 32K. It's just that I have a bug with some rather big strings 9+K not passing over a socket connection and I just wanted to make sure that the CString was not the cause of it. Greetings, Davy

                      M Offline
                      M Offline
                      Mark Salsbery
                      wrote on last edited by
                      #10

                      GDavy wrote:

                      It's just that I have a bug with some rather big strings 9+K not passing over a socket connection

                      String length isn't the problem, but what's going on with your sockets? Mark

                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                      1 Reply Last reply
                      0
                      • G GDavy

                        hello, I remember reading once that a CString object has a maximum amount of characters it can hold, I just can't seem to find how much that is. Does anybody know how much that count is? If you have a URL with that info that would also be neat. Greetings, Davy

                        H Offline
                        H Offline
                        Hamid Taebi
                        wrote on last edited by
                        #11

                        Can you say why do you need to max length of CString,please?

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups