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

Handling large memory blocks of dynamic length in an efficient way

P: n/a
Hi all,
I'm looking for a class to access large memory blocks of dynamic
length in an efficient way.

Basically the simplest way to allocate a memory block is to allocate a
byte [].

If you now want that this memory block can grow dynamically, then you
usually allocate a byte [] of a certain size, then if size is
outgrown, you create a bigger byte [] and copy the old one to the new
one. This is usually wrapped into a class (I think StringBuffer does
that).

Now the problem with this is, imagine your memory block is already,
say, 100 Meg, now you allocate a new one with 120 Meg, copy the 100
Meg over, and leave the old block to garbage collection. This might
just not be possible if you are low in free memory.

I want to have something more advanced: The memory block is internally
separated into many small blocks - if it grows, only a new small block
needs to be allocated. Of course a class wrapping this would need to
provide functions to take data out of one or more blocks and put them
back together in a continous byte [].

So my question is, does something like this already exist, or do I
need it to write myself?

Thanks,
Markus
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Markus L?ffler" <ma****@loffler.de> wrote in message
news:7a**************************@posting.google.c om...
Hi all,
I'm looking for a class to access large memory blocks of dynamic
length in an efficient way.

Basically the simplest way to allocate a memory block is to allocate a
byte [].

If you now want that this memory block can grow dynamically, then you
usually allocate a byte [] of a certain size, then if size is
outgrown, you create a bigger byte [] and copy the old one to the new
one. This is usually wrapped into a class (I think StringBuffer does
that).

Now the problem with this is, imagine your memory block is already,
say, 100 Meg, now you allocate a new one with 120 Meg, copy the 100
Meg over, and leave the old block to garbage collection. This might
just not be possible if you are low in free memory.

I want to have something more advanced: The memory block is internally
separated into many small blocks - if it grows, only a new small block
needs to be allocated. Of course a class wrapping this would need to
provide functions to take data out of one or more blocks and put them
back together in a continous byte [].

So my question is, does something like this already exist, or do I
need it to write myself?

Thanks,
Markus


See ByteArrayOutputStream and ByteArrayInputStream. And also the java.nio
package if you want to get more technical
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.