What is the maximum length in characters a CString object can hold?
Asked
Active
Viewed 1.9k times
3 Answers
12
Up to your available memory or INT_MAX-1 (whichever is less).

Franci Penov
- 74,861
- 18
- 132
- 169
-
It should always be INT_MAX-1, because even if you only have 100megs of RAM, virtual memory will store the rest. – Orion Edwards Oct 08 '08 at 00:00
-
@Orion: only to a point. On 32-bit Windows, user-mode programs will have somewhat less than 2GB of address space available (since the program itself will take up some space). – Shog9 Oct 08 '08 at 00:04
-
The length is not limited only to the available memory, but to the size of the largest available continuous memory block. Which could be less than INT_MAX-1, depending on what else you have loaded in the memory and how fragmented your heap is. – Franci Penov Oct 08 '08 at 00:04
-
1He asked for the length in characters, not bytes, so the size of the character matters: `sizeof(TCHAR)` could be 1 or 2 depending on whether `UNICODE` is `#define`ed somewhere. – Brian Ensink Oct 08 '08 at 03:34
-
1@Nathan Yellin - because one char is reserved for the terminating `\x0` char – Franci Penov Aug 17 '11 at 16:20
-
1@Nathan Yellin - soery, answered the wrong question. It's INT_MAX, because the variable holding the length is of type int. – Franci Penov Aug 18 '11 at 15:18