Space allocation

A

Andi Hotz

Hi,

I have to write an application to compress data, which is a pointer to the
start of the data and the length of the data in bytes. When I want to
compress the data should decrease. So how do I allocate the needed space? I
had two ideas:
- Use of a vector of char
- Copy of the uncompressed file and use the space of the copy for the
copressed data.
Does anyone see another possibility? Which one is the best?

Andi
 
H

Howard

Andi Hotz said:
Hi,

I have to write an application to compress data, which is a pointer to the
start of the data and the length of the data in bytes. When I want to
compress the data should decrease. So how do I allocate the needed space? I
had two ideas:
- Use of a vector of char
- Copy of the uncompressed file and use the space of the copy for the
copressed data.
Does anyone see another possibility? Which one is the best?

Andi

Well, a lot depends upon how big the data is. You say you pass a pointer to
the data and its length, so that must mean that it's in memory already. So
files are irrelevant. You can always allocate an equal amount of space,
since you know it will always be less. A vector sounds easy enough, but
possibly overkill for simple char's. Or you can just use "new char[size]"
(and later, "delete[]"). Again, though, it depends how you're doing the
compression. Are you going over the data more than once, applying multiple
compression techniques? Or is it just once through the source, creating the
destination? Perhaps you can even do the compresssion in place, not
allocating any new space at all? The algorithm you've chosen should
indicate what an appropriate method would be.

-Howard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
EmeliaBryc

Latest Threads

Top