By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,382 Members | 1,688 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,382 IT Pros & Developers. It's quick & easy.

Size constraints in C++

P: 3
Hi,
I am doing a program with data compression and was wondering if there are any sort of limits on vectors that I did not know about. The program works perfectly as long it is under about 2100 characters, however, if I try to compress anything longer it encodes it, but when I decode it it gives me really random symbols 箸ق㧰ف獲潩㵮ㄢ〮湥潣楤杮∽楗摮 like these along with a lot of extra boxes. I thought it was a character array at first, but I switched all of them to vectors and it still does this.

Thanks for any help,
husker14
May 31 '07 #1
Share this Question
Share on Google+
7 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
A vector containing what type?

vector<T>::max_size() will give you the number of elements you can have in the vector. This says nothing about the size of the elements.

I have personally used a vector of a million doubles with no problem.

But this:
program works perfectly as long it is under about 2100 characters
doesn't say what it is.

Those odd characters look like a display of non-ASCII values which makes me think you have some memory corruption operating.
May 31 '07 #2

P: 3
It is a vector of chars, if that helps.
Jun 1 '07 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
unless there is a way to convert wchar_t to char?
A vector is an array. The C++ spec specifically says vector must implement a C array. Therefore, if your code works with a char array it will work as a vector.

Now you mention encoding/decoding and you mention a vector of char. I assume you meant a vector of unsigned char. Right?
Jun 1 '07 #4

Expert 10K+
P: 11,448
A vector is an array. The C++ spec specifically says vector must implement a C array. Therefore, if your code works with a char array it will work as a vector.

Now you mention encoding/decoding and you mention a vector of char. I assume you meant a vector of unsigned char. Right?
The (Chinese?) characers I saw in the OP's example have unicode values far
beyond the range [0,255]. My guess is that the vectors are at least vectors of
unsigned shorts or some utf/8 decoding must be trying to decode those values.
Without seeing any code all I can conclude is that there's definitely something
rotten in the state of Denmark ;-)

kind regards,

Jos
Jun 1 '07 #5

AdrianH
Expert 100+
P: 1,251
Given all the info so far, I'd say it is a problem with your compression algorithm. It is very doubful that it is related to the STL vector class. It should be able to hold (at least) 2.1GiB as long as your OS and computer requirements supports it.

2100 is about 11 bits so I don't see why around that number would cause a problem.


Adrian
Jun 1 '07 #6

P: 3
I figured out what was going wrong. The problem was an integer was getting too big and so it was turning it into a negative number and screwing everything up.
Thanks for all of your help.
Jun 1 '07 #7

AdrianH
Expert 100+
P: 1,251
I figured out what was going wrong. The problem was an integer was getting too big and so it was turning it into a negative number and screwing everything up.
Thanks for all of your help.
No prob.


Adrian
Jun 1 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.