• Post Reply Bookmark Topic Watch Topic
  • New Topic

Storing Data Using ?DoubleBuffer?  RSS feed

 
Don Gardner
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on a program that will create a graph from sets of x-y data arrays. I want the to be able to hold an undefined number of data sets of the type double.
It thought that DoubleBuffer was my silver bullet, but it turns out that it is abstract, and I don't know what I need to do to make it useable.
So I have two questions:
1) Do you all think that DoubleBuffer is the way to go or can you think of a better way to do what I want?
2) If DoubleBuffer is the way to go, how do I implement the abstract class to make it usabe, or where can I find said information?
I've looked at Sun's website, but I haven't been able to find a tutorial on and every reference to DoubleBuffer on the web and on JavaRanch that I have been able to find are actually referencing double buffering of images.
If anyone could give me a hint, I would greatly appreciate it.
Thanks,
Don
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure whether java.nio.DoubleBuffer will be of use to you or not; you may be able to find out by reading the New I/O documentation on Sun's web site.
 
Igor Ko
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you speak about double buffer for pictures:
see:
http://java.sun.com/products/jfc/tsc/articles/painting/
see also:
http://java.sun.com/docs/books/tutorial/2d/images/doublebuffering.html
and
http://java.sun.com/docs/books/tutorial/uiswing/14painting/concepts2.html

Double buffer conception also used in file I/O.
It is the same idea: During the time when one buffer reading/writing from/to
disk (screen), make something with other buffer.
[ December 24, 2003: Message edited by: Igor Ko ]
 
Don Gardner
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I'm not talking about double buffering for images, and that is all I've been able to find when I've done a search for information on DoubleBuffer. I am talking about the class java.nio.DoubleBuffer that Ernest mentioned. Of course, I'm not sure whether this is the appropriate class for me to be using or not.
Maybe if I give some more detail you might be able to help. I want to be able to plot 2xN arrays of data, but want to be able to store an unspecified number of data sets for re-plotting and re-scaling. I could just use a array of 2D arrays, but there would be a limit as to how many data sets I could store, or I would have to recast the data to hold additional data sets.
I thought that I had remembered that you could use buffers in this way. You could create a buffer, and it would dynamically allocate space for however many data sets you added to it. Then I say the DoubleBuffer class, which is a buffer specifically for holding data of the type Double, and I thought that was exactly what I needed.
Unfortunatley, I can't figure out how to implement it.
I'll take a look at the New I/O Documentation and see what is there, but I have a feeling that it will tell me that DoubleBuffer isn't what I need.
Thanks for the help,
Don
 
Joe Ess
Bartender
Posts: 9443
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use ByteBuffer.asDoubleBuffer() to create a DoubleBuffer "view" of a ByteBuffer. This is convenient since ByteBuffer has an implementation in MappedByteBuffer. However, I see that you want to use buffers as dynamic storage. Buffers are allocated with a size argument. Not sure if this spoils your plans or not. You have to wrap the buffer with some logic anyway, since you want to store points. You can include some size management logic in there too.
 
Don Gardner
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, Buffers require size managment? I wasn't aware of that. I could have sworn that there was some sort of class that took care of size management for you. I guess I'm thinking of another language, or just smoking crack.
Can you point me to information about how to handle size management? Is there any benifit to using buffer instead of:
-just creating an array of size 10 (or 5, or whatever)
-stuffing my data sets in there
-when that array is full, re-create the array with a size of 20 (or 10, or whatever)
-etc.
[ December 29, 2003: Message edited by: Don Gardner ]
 
Joe Ess
Bartender
Posts: 9443
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Don Gardner:
I could have sworn that there was some sort of class that took care of size management for you.


Perhaps you were thinking of java.io.ByteArrayOutputStream? You could wrap it with ObjectOutputStream and write primitives (i.e. double) or Object instances to it, then recover them through at your leasure with the corresponding *InputStreams.

Is there any benifit to using buffer instead of. . .

The benefits to using a memory-mapped (i.e. java.nio.MappedByteBuffer) file are 1. data not stored in the JVM's memory (good if you have tons of data) and 2. mappings to the same physical file share the same virtural memory, so changes can be made to the file and see by all apps that share it.
 
Don Gardner
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I wasn't planning on saving the data to a file at the moment. I am creating this class to reuse for other programs to handle the creation of plots and the plotting of data.
So, any file that I create with this class would be a temporary file, and I would like to be able to use this class with applets as well as applications. From my understanding, you cannot use temp files for applets because of security limitation.
So, from this, I'm thinking that a memory-mapped file isn't the way I want to go.
Thanks for all of the help. I hope to get this figured out in the next week or so, time permitting. I would like very much to get some commentary on my code, so I think I'll post a link to it, and see if anyone will critique it.
Thanks again,
Don
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!