Space allocation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andi Hotz

    Space allocation

    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


  • Howard

    #2
    Re: Space allocation


    "Andi Hotz" <andi.hotz@adsl .li> wrote in message
    news:3fba0fcd$0 $714$5402220f@n ews.sunrise.ch. ..[color=blue]
    > 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?[/color]
    I[color=blue]
    > 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
    >[/color]

    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




    Comment

    Working...