Fast way to read and write console

hi guys
what's the fastest way to read and write from console?
For writing I'm using (I think thats the fastest way)
System.out.println(foo)and I have to read the following - all numbers are ints (that means m + n + 1 lines):
1 * "<n> <m>"
n * "<a> <b> <c>"
m * "<a> <b>"Actual I'm reading (the second line for example) with
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] items = br.readLine().split("[^\\-\\.0-9]+");
Target mainTarget = new Target(Integer.parseInt(items[0]), Integer.parseInt(items[1]), Integer.parseInt(items[2]));
for (int i = 1; i < m; i++) {
    items = br.readLine().split("[^\\-\\.0-9]+");
    mainTarget.addTarget(Integer.parseInt(items[0]), Integer.parseInt(items[1]), Integer.parseInt(items[2]));
} But that isn't really fast...
have you any idea?
grz faetzminator

faetzminator wrote:
right, I have 1 + 1 + 1 =3 up to 10^6-1 + 10^6-1 + 1 =2*10^6-1 input lines with max 4999997 integers (and I have to store 2999999 of them)
ok, if that is the fastest way... (maybe the reading of the input file is so slow; I run eg "java Foo < input > output")All those br.readLine calls where you never check if the return is null are dangerous.
I really don't understand what you are doing. You mentioned System.in at first and now reading from files.
I also am pretty sure that you are in fact running out of memory.

Similar Messages

  • Fast, small-byte reads and writes.

    I am trying to communicate with a third-party counter using a 1 byte "start" command followed by reading a 4 byte number.  I would like to perform this read/write pair as fast as possible as I will be using count-times on the order of microseconds repeated millions of times.  Our first attempt used USB but the latency in the bus was way too slow at 1ms.  We spent more time waiting than counting. We are currently considering GPIB since the latency should be only 30 microseconds but we're concerned that the overhead from labview will prevent us from reading and writing that fast.  Another idea we had was to use digital I/O channels to create our own parallel port to by-pass the USB bus.  Can anyone comment on a good solution for low-latency small-byte reads and writes from labview? What type of hardware is recommended and can labview support programmatic reads-writes on the order of microseconds? Thanks!

    Theoretically GPIB is capable of very good latencies, as you say on the order of usec.  But in the real world using real PCs running real operating systems and connected to real instruments, the latencies seem to cluster around 2-5msec, in my experience.  The issue isn't LabVIEW so much as all the stuff through which instrumentation interactions must filter, including background processes, screen updates and all the rest of the activities which consume the processor's bandwidth.  Some instruments allow you to buffer and interpret the next command while the current one is underway, then trigger it, which saves latency.  Also keep in mind that your GPIB network will only be as responsive as the least-well-behaved instrument on the bus.

  • How many ways to read and write a local variable in a called VI?

    Ciao!
    I'm producing my first TestStand sequence. It is called "FirstAttempt" and it is made by a single step which calls a VI. One of the first dilemmas i encountered realizing this sequence is how to read and write a local variable (created going in Variables -> Locals ('FirstAttempt') -> <right click to insert local>) in the called VI.
    The first way (the only one i tried) is to create a control and an indicator on the VI front panel, connect them to their respective terminals in the connector pane and then specify (going in Step Settings -> Module) that these connectors (shown in the Parameter Name column) are linked to the local variable (selected in the Value column).
    The second way (not tried) consists in using TestStand API: create a Sequence Context reference on the VI front panel, link it to a property node in the block diagram, select the property "Locals" and extract from this the local variable name and value which, i think, can be readable and writable.
    So...
    Are the shown ways correct?
    Are there other ways?
    Knowing that a "local" variable can be considered "global" within the whole sequence, is there the possibility to simply create a reference to the local variable and use the reference in the called VI block diagram in order to save space in the connector pane (if using method 1) or in the block diagram (if using method 2)?
    Thanks!
    Message Edited by aRCo on 09-17-2009 05:09 AM

    Hi,
    Before TestStand 3 you would use the second way you quoted as its the only way.
    But now you would use the first way you quoted. You may still what to pass the SequenceContext if you were going to use the TestStand API. For TestStand 3.x and above you would use this way as the first chose. (Personnelly, I would not pass the SequenceContext into a VI if I know it was never going to be used in that VI.)
    Not sure I understand your final comment, maybe you are liking it to passing the reference of a control to a subVI so that the control can be updated from within the subVI.
    If this is the case and you had a situation where you had a step that was running in parallel with the rest of the steps in the sequence either as a separate thread or execution and were dependent on the contents of the  local variable changing from that parallel running step, then you would have to use the API SetVal method to change the local.
    Hope this is clear.
    Regards
    Ray Farmer
    Regards
    Ray Farmer

  • Best way for read and write?

    Hello
    I'm working on project with labview .
    with this program i connecting PC to the MCU through sreial RTU modbus .
    in this program there are some data need to be read and some data need to write .
    what i need is most of my time reading polet exuted exept when some of  control element (like edit box) has changed by user .
    when ever some thing changed by user write polet excuted .
    now what is the best way to do this ?
    Best Regards.
    Solved!
    Go to Solution.

    mori64 wrote:
    What uou said sound complicated to me .
    i'm trying to undrestand your solution .
    i'll be happy if you upload sample program .
    State Machine
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Fastest way to read and write to/from muliple DAQ channels

    I'm developing an application in which multiple DAQ channels will be monitored, for example, displacement, load, strain, temperature and so on. My question is what is the fastest and most efficent way to check the value of these inputs, compare them to user inputs and then decide whether or not to write a different voltage to an output. I'm using LV 7.1 on Win 2000.

    I guess my first question would be are all these channels going to be on one card? Are you going to just make single measurements (are you interested in instantaneous values vs. "waveforms")? Doing a "Sample channels" for instance will make a single measurement of several channels (on the same board) and present you with an array of the resulting data, one element per channel. How fast do you need to sample, are all of the signals going to be on the same board? The latest NI-Daq allows configuring tasks that mix channel types (T'couples, straight voltage measurements, etc.) which makes configuring the DAQ easier.
    If you can give us a little more information regarding what you are trying to accomplish it will help.
    P.M.
    Putnam
    Certified LabVIEW Developer
    Senior Test Engineer
    Currently using LV 6.1-LabVIEW 2012, RT8.5
    LabVIEW Champion

  • How to increase disk read and write speed after installing new SSD (2009 Macbook Pro)? Why not as fast as advertised?

    Hi everyone,
    I just installed a Crucial MX10512 GB SSD into my 2009 Macbook Pro. It's definitely much faster, but the read and write disk speed is around 200 Mb/s for both versus the 300-500 Mb/s that the SSD advertised. Any ideas as to why? And is there anything I can do to make it faster? Before I installed it, it was between 80-90 Mb/s.
    Specs:
    - currently have about 460 of 511 GB of storage available
    - am using 2GB of memory
    - running on 10.10.2 Yosemite
    Thanks!

    nataliemint wrote:
    Drew, forgive me for being so computer-incompetent but how would I boot from another OS? And shouldn't I be checking the read speeds on my current OS (Yosemite) anyways because I want to know how the SSD is performing on the OS I use? And finally, what kind of resources would it be using that would be slowing down my SSD?
    Sorry for all the questions - I'm not a Macbook wiz by any means!
    You could make a clone of your internal OS onto an external disk. Hopefully you already have a backup of some form
    A clone is a full copy, so you can boot from it. It makes a good backup as well as being useful to test things like this.
    Carbon Copy Cloner will make one or you can use Disk Utility to 'restore' your OS from the internal disk to an external one.
    Ideally the external disk is a fast disk with a fast 'interface' like Thunderbolt, Firewire 800 or USB3. USB2 can work, but it is slow & may effect the test.
    You connect the clone, hold alt at startup & select the external disk in the 'boot manager'. When the Mac is finished booting run the speed tester.
    Maybe this one…
    https://itunes.apple.com/gb/app/blackmagic-disk-speed-test/id425264550
    Test the internal & compare to the previous tests
    A running OS will do the following on it's boot disk…
    Write/ read cache files from running apps
    Write/ read memory to disk if memory is running low
    Index new files if content is changing or being updated
    Copy files for backing up (Time Machine or any other scheduled tasks)
    Networking can also trigger read/ write on the disk too.
    You may not have much activity that effects a disk speed test, but you can't really be sure unless that disk is not being used for other tasks.
    Disk testing is an art & science in itself, see this if you want to get an idea …
    http://macperformanceguide.com/topics/topic-Storage.html
    Simply knowing that it's about twice the speed would be enough to cheer me up

  • Is there a way to use the FF vi's to read and write complex data types; specifically, clusters?

    I'm trying to interface with a Fieldbus device through LabVIEW.  I need to be able to read and write a variable that consists of a cluster of two unsigned int 32's.  The FF vi's provided with FF Communications Manager 3.2 do not support clusters.  I have tried to use a code interface node to write my own, but the CIN's I was using before to do this function do not give me a device list anymore (they were originally written on Communications Manager 2.3.5).  I have recompiled the .lsb, as well as trying to use the older versions of the header and library files.  Is there another workaround I can use?

    Hello Bryan,
    The BrowseDeviceList VI was released within NI-FBUS 3.2. For NI-FBUS Configurator 3.1, please unzip the attached file and copy the "addon" and "Ff" folders into "\vi.lib" directory. LabVIEW 7.1 or above version is required for using these addons.
    And for your information, there is a free upgrade (version 3.1.1) for NI-FBUS Configurator 3.1 users. Here is the link to the upgrade kit.
    http://digital.ni.com/softlib.nsf/websearch/00A1614EC291219586256F390020671B?opendocument&node=132070_US
    Hope it helps!
    Regards,
    --Josiane
    Attachments:
    locate_fflv_in_labview82.jpg ‏214 KB
    vi.lib.zip ‏391 KB
    locate_fflv_in_labview71.jpg ‏193 KB

  • How to read and write a string into a txt.file

    Hi, I am now using BEA Workshop for Weblogic Platform version10. I am using J2EE is my programming language. The problem I encounter is as the above title; how to read and write a string into a txt.file with a specific root directory? Do you have any sample codes to reference?
    I hope someone can answer my question as soon as possible
    Thank you very much.

    Accessing the file system directly from a web app is a bad idea for several reasons. See http://weblogs.java.net/blog/simongbrown/archive/2003/10/file_access_in.html for a great discussion of the topic.
    On Weblogic there seems to be two ways to access files. First, use a File T3 connector from the console. Second, use java.net.URL with the file: protocol. The T3File object has been deprecated and suggests:
    Deprecated in WebLogic Server 6.1. Use java.net.URL.openConnection() instead.
    Edited by: m0smith on Mar 12, 2008 5:18 PM

  • Instrument i/o assistant always generates async methods for read and write!

    I am trying to generate VI by instrument i/o assistant, but it generated 'Visa write' and 'Visa read' always in asynchronous mode. Even if I unchecked asynch boxes in MAX->Visa Test Panel.
    I need only synchronous mode! And it is very uncovenient after open front panel change  Synchronous I/O Mode from Asynchronous to Synchronous!

    postoroniy_v wrote:
    Asynchronous mode does not work for my hardware.
    and before Instrument i/o assistant  generate diagram I have possibility to check requests and responses to/from my hardware. in this case everything is fine.
    after generate  does not work.
    Is it possible you don't have a sufficient amount of wait time between a VISA Write and VISA read to give the instrument time to receive the communication and turn around a response?  Take a look at Basic Serial Read and Write example VI.  If you are using the I/O assistant and checking things manually, it will work because there is no way you can generate a Read too fast.  It still would take a fraction of second to generate the write and do whatever clicking to generate the read.

  • I'm trying to share folder between users on a single mac.  I put the folder in "shared," set permissions so other user can read and write, enabled file sharing, but can't find the folder on the second user's account.  Any help?

    I'm trying to share a folder between users on a single mac.  I want both users to be able to read and write so the folder stays current on both accounts.  I put the folder in "shared," set permissions on folder so other user can read and write, enabled file sharing, but can't find the folder on the second user's account.  Any help?

    Did you log out of one account and into the other or just used Fast user switching?
    Is the permissions set to anyone?
    When you move data to teh Shared folder is it copied or just moved?
    If copied then it's not a folder both can access, just a way station like a USB thumb drive that things are coped too and off of likely.
    You can run this #5 on each user account to reset the user permissions once they are taken back out of the Shared folder
    Step by Step to fix your Mac

  • Need help to read and write using UTF-16LE

    Hello,
    I am in need of yr help.
    In my application i am using UTF-16LE to export and import the data when i am doing immediate.
    And sometimes i need to do the import in an scheduled formate..i.e the export and imort will happend in the specified time.
    But in my application when i am doing scheduled import, they used the URL class to build the URL for that file and copy the data to one temp file to do the event later.
    The importing file is in UTF-16LE formate and i need to write the code for that encoding formate.
    The problem is when i am doing scheduled import i need to copy the data of the file into one temp place and they doing the import.
    When copying the data from one file to the temp i cant use the UTF-16LE encoding into the URL .And if i get the path from the URl and creating the reader and writer its giving the FileNotFound exception.
    Here is the excisting code,
    protected void copyFile(String rootURL, String fileName) {
    URL url = null;
    try {
    url = new URL(rootURL);
    } catch(java.net.MalformedURLException ex) {
    if(url != null) {
    BufferedWriter out = null;
    BufferedReader in = null;
    try {
    out = new BufferedWriter(new FileWriter(fileName));
    in = new BufferedReader(new InputStreamReader(url.openStream()));
    String line;
    do {
    line = in.readLine();
    if(line != null) {
    out.write(line, 0, line.length());
    out.newLine();
    } while(line != null);
    in.close();
    out.close();
    } catch(Exception ex) {
    Here String rootURL is the real file name from where i have to get the data and its UTF-16LE formate.And String fileName is the tem filename and it logical one.
    I think i tried to describe the problem.
    Plz anyone help me.
    Thanks in advance.

    Hello,
    thanks for yr reply...
    I did the as per yr words using StreamWriter but the problem is i need a temp file name to create writer to write into that.
    but its an logical one and its not in real so if i create Streamwriten in that its through FileNotFound exception.
    The only problem is the existing code build using URL and i can change all the lines and its very difficult because its vast amount of data.
    Is anyother way to solve this issue?
    Once again thanks..

  • Best Practice to Atomic Read and Write a Field In Database

    I am from Java Desktop Application background. May I know what is the best practice in J2EE, to atomic read and write a field in database. Currently, here is what I did
    // In Servlet.
    synchronized(private_static_final_object)
        int counter = read_counter_from_database();
        counter++;
        write_counter_back_to_database(counter);
    }However, I suspect the above method will work all the time.
    As my observation is that, if I have several web request at the same time, I am executing code within single instance of servlet, using different thread. The above method shall work, as different thread web request, are all referring to same "private_static_final_object"
    However, my guess is "single instance of servlet" is not guarantee. As after some time span, the previous instance of servlet may destroy, with another new instance of servlet being created.
    I also came across [http://code.google.com/appengine/docs/java/datastore/transactions.html|http://code.google.com/appengine/docs/java/datastore/transactions.html] in JDO. I am not sure whether they are going to solve the problem.
    // In Servlet.
    Transaction tx = pm.currentTransaction();
    tx.begin();
        int counter = read_counter_from_database();  // Line 1
        counter++;                                                  // Line 2
        write_counter_back_to_database(counter);    // Line 3
    tx.commit();Is the code guarantee only when Thread A finish execute Line 1 till Line 3 atomically, only Thread B can continue to execute Line 1 till Line 3 atomically?
    As I do not wish the following situation happen.
    (1) Thread A read counter from Database as 0
    (2) Thread A increment counter to 1
    (3) Thread B read counter from Database as 0
    (4) Thread A write counter as 1 to database
    (5) Thread B increment counter to 1
    (6) Thread B write counter as 1 to database
    What I wish is
    (1) Thread A read counter from Database as 0
    (2) Thread A increment counter to 1
    (4) Thread A write counter as 1 to database
    (3) Thread B read counter from Database as 1
    (5) Thread B increment counter to 2
    (6) Thread B write counter as 2 to database
    Thanks you.
    Edited by: yccheok on Oct 27, 2009 8:39 PM

    This is my understanding of the issue (you should research it further on you own to get a better understanding):
    I suggest you use local variables (ie, defined within a function), and keep away from static variables. Those local variables are thread safe. If you call functions within functions, its still thread safe. If you read or write to one record in a database using sql, its thread safe (you dont need a transaction). If you read/write to multiple tables and/or records, you probably need a transaction. Servlets are thread safe. You usually dont need the 'synchronized' word anywhere unless you have a function updating/reading a static variable and therefore want to ensure only one user is accessing the static varible at a time. Also do so if you are writing to some resource (such as a file, a variable in applicaton scope, session scope, or resource that everyone uses such as email server). You dont want more than one person at a time to write to it). Note the database is one of of those resources that is handled by transactions rather than the the synchronized keyword (the synchronized keyword is applied to your application only (not other applications that someone is running), whereas the transaction ensures all applications are locked out while you update those records in the database).
    By the way, if you have a static variable, you should have one and only one function (synchronized) that updates it that everyone uses. If you have more than one synchronized function, that updates it, its probably not thread safe.
    An example of a static variable you would use is a Datasource object (to obtain your database connections). You only need one connection pool in your application and you access it via the datasource variable.
    If you're unsure your code is thread safe, you can create two seperate threads that call the same block of functions repeatedly to ensure it works as expected.

  • ITunes Library on an Airport Disk?  Read and write from multiple Macs?

    OK, I've scoured the forums for an answer to this, but haven't found anything definitive. Apologies if I've missed the answer, but here's what I want to know:
    I have an iMac as a primary computer, plus a Mac Mini hooked up to my entertainment system, and my girlfriend's powerbook in the house too. There seem to be two main iTunes options: either constantly try to keep all three iTunes libraries synchronised by running around importing files, etc.; or just keep one library, and share it over the network.
    Right now, I am keeping my iTunes library on my iMac and sharing it with the Mac Mini and the powerbook. If anyone wants to add music (or other content) to the library, it has to be through the iMac. Obviously the iMac has to be on for any other computer to access the shared library.
    I want to try to make things simpler by having a single "network" iTunes library that all computers to be able to share (read AND write). I envisage having this "iTunes Server" on an external HD connected to my Airport Extreme as an Airport Disk. If I move the entire contents of ~/music/iTunes (including artwork, library files, etc) to this central location, will the three Macs be able to deal with this, ie can multiple computers share an iTunes library database on an airdisk? Will I be able to stream content from this library to all three computers? Will I be able to import new music into the library from any one of the three computers?

    I am having a very similar problem. I have all of my music saved on a large external disk connected to my airport. I would like to be able to just play what i want from this disk, but i don't like having to download every track i want to listen to. I still want to be able to bring my laptop with me and have some music so i don't want to make this external disk my library folder. Is there a way to play it on my computer similar to a shared library on another computer? Am i asking to much out of apple?

  • Read and Write data in iphone app

    I want to build a simple offline mobile app which reads and writes or stores info to a file, xml, json, txt or whatever.
    What is the best way to do this?
    I am currently learing jQuery and PHP, so I don't want to have to learn some other million things that does one thing but not another.
    Can this be achived without objective C? Can i do this with Jquery and phone Gap?
    Thanks

    Do a search for 'HTML 5 Storage' and you'll find a bunch of resources that will help. Here's a few
    http://www.w3schools.com/HTML/html5_webstorage.asp
    http://diveintohtml5.info/storage.html
    http://htmlpad.wordpress.com/2010/03/10/html-5-data-storage-javascript-api-on-ipad-and-iph one/

  • How to read and write a data from extrenal file

    Hi..
    How to read and write a data from extrenal file using Pl/sql?
    Is it possible from Dyanamic Sql or any other way?
    Reagards
    Raju

    utl_file
    Re: How to Create text(dat) file.
    Message was edited by:
    jeneesh

Maybe you are looking for

  • How do you import pictures from an iPhone to a Mac?

    I know you can import using iPhoto but I do not care for the applications one file approach. Meaning, importing via iPhoto just adds them to the overall library file, not individually where they can be easily moved around. Typically, when I only had

  • Minimum specs for use as a media centre?

    I would like to have a Mac Mini hooked up to my tv to use as a media centre. i have worked out that i will be able to use it without a keyboard mouse etc by setting it up so front row or vlc load up on boot and using the remote, so am ok there... my

  • ABAP routine for loading data of current month in InfoPackage

    Hello experts, I want to load data of current month. Therefore I implemented the following ABAP-Routine for field 0CALDAY in the InfoPackage's data selection: data: lv_datum_l like sy-datum,          lv_datum_h like sy-datum.    concatenate sy-datum(

  • How do I save my edits in iPhoto and/or Aperture?

    I have edited an image in iPhoto and again in Aperture and can't find either. The original remains. I can find no "Save" option and assumed that it was automatic. If so, where does it go? Is there a "save as" option?

  • Cursor snap to bar in arrange view

    Is it possible for the cursor to snap to the bar or beat when I click in the arrange view like in garageband? I have messed around with the different snap to settings but the cursor will not snap to the division bars, how do I do this?