bad allocation error

The code below is giving me a bad allocation error, I think it may be due to the size which is 4294965747.

char * array = new char[size]

Where am I going wrong, can a char array be the required size and if not what other data structure should I use.
You are trying to allocate 4 GB of memory. Do you ahve that much spare memory avaliable? Do you have 64 bit system to allow to use that much memory?

Either way I doubt that you will have continuous 4GB of memory avaliable due to memory fragmentation.

You can try std::deque as it allows non-contiguous memory while retaining almos all speed of arrays.
What do you need so much memory for?
You can try std::deque as it allows non-contiguous memory while retaining almos all speed of arrays.
Cache coherency can be a bitch sometimes, and not having it can really slow down a program. I wouldn't say "almost" the speed, because the difference can be a lot.
Cache coherency can be a bitch sometimes, and not having it can really slow down a program. I wouldn't say "almost" the speed, because the difference can be a lot. Cache coherency
Depending on one block size. Generally, proper deques are optimised to minimize perfomance impact.

No matter what, he is not going to have 4GB array. Deque is as close as he is going to get (sequental, random access)
Thanks guys some other part of the code actually needs that much, I didn't realise must be an something wrong.
some other part of the code actually needs that much
At the same time? I do not believe that you cannot separate calculations on several steps and have only relatively small amount of data in memory at the time.
No matter what, he is not going to have 4GB array. Deque is as close as he is going to get (sequental, random access)
Fair enough.

@OP

Can you answer this question?
What do you need so much memory for?
Last edited on
Topic archived. No new replies allowed.