473,786 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Handling large memory blocks of dynamic length in an efficient way

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
1 2302

"Markus L?ffler" <ma****@loffler .de> wrote in message
news:7a******** *************** ***@posting.goo gle.com...
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 ByteArrayOutput Stream and ByteArrayInputS tream. And also the java.nio
package if you want to get more technical
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3538
by: Joseph | last post by:
Hi, I'm having bit of questions on recursive pointer. I have following code that supports upto 8K files but when i do a file like 12K i get a segment fault. I Know it is in this line of code. How do i make the last pointer in the indirect sector that has another level of indirect pointer, and be defined recursively to support infinite large files? -code-
3
2712
by: Sourin | last post by:
Hi all, I am trying to write code for my experiments. My work involves huge datasets, and as such my code needs to be memory efficient. I did some hand calculations regarding the amount of dynamic memory required for my datastructures ( used sizeof() to get the size of the structures ). But mallinfo() function show that approximately double that amount of memory is being allocated. I am working with gcc 3.2.2 on a redhat 9 machine. I...
6
2374
by: Peter Hickman | last post by:
I have a program that requires x strings all of y length. x will be in the range of 100-10000 whereas the strings will all be < 200 each. This does not need to be grown once it has been created. Should I allocate x strings of y length or should I allocate a single string x * y long? Which would be more efficient and / or portable? Thank you.
12
2310
by: ira2402 | last post by:
Hi All, We are developing sw for a small embedded OS and we have limited memory. We are looking for algorithms, links, and articles about this. The goal is efficient utilization of small amount of memory - means - allocation for fixed length blocks / variable length blocks. Thanks.
1
4013
by: lwickland | last post by:
Summary: System.Net.ScatterGatherBuffers.MemoryChuck allocates inordinately large bytes when sending large post data. The following application consumes inordinate quantities of memory. My code does not explicitly allocate memory in a loop nor does it explicitly allocate large blocks of memory. Yet, the application’s memory footprint will grow as large as 370 MB. Rarely will it run to completion; usually, it throws an out of memory...
14
3898
by: Al Smith | last post by:
I need help in implementing proper error handling. I am trying to upload a file based on the sample code below. The code works well except if the file selected is too big. I do know about the maxRequestLength parameter of the <httpRuntime> section and that works as expected. What I want is to enforce a max file size but haven't been able to trap the error thrown when the file is too large and that's where I could use some help.
3
1656
by: douglas wittner | last post by:
morning all, can someone help me find the most efficient way of manipulating a large file. i need to replace special characters in a large file and multiple string.replace functions are causing memory errors. doug
66
3644
by: Johan Tibell | last post by:
I've written a piece of code that uses sockets a lot (I know that sockets aren't portable C, this is not a question about sockets per se). Much of my code ended up looking like this: if (function(socket, args) == -1) { perror("function"); exit(EXIT_FAILURE); } I feel that the ifs destroy the readability of my code. Would it be
8
1932
by: Francine.Neary | last post by:
I'm experimenting with a program that manipulates a large matrix, i.e. a 2-deep array. I started by just allocating this in one go, but later it occurred to me that, as there are still some very old systems around where such a large allocation might fail, perhaps it would be better to split the allocation into many allocations, one for each row, to increase portability to legacy systems. The advantage I see is that the memory allocator...
0
9497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8992
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6748
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.