Noobish "efficiency" question on DataOutputStream

So, I currently have this:
byte[] buf = some_bytes;
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
out.writeInt(buf.length);
out.write(buf);I've always thought that calling write(byte[]) and any given OutputStream will be "efficient", in that things will be chunked under the hood to avoid incurring whatever I/O overhead is present for each and every byte. So, as I understand it, we only need to explicitly use BufferedOutputStream if we're writing one or a few bytes at a time.
Now I'm not so sure.
Digging through the core API source code a bit, it seems that this ultimately calls OutputStream.write(byte) in a loop, which, presumably, is bad unless the OutputStream in question is a Buffered one.
Am I shooting myself in the foot here? Should I be wrapping that DataOuputStream around a BufferedOutputStream? Or vice versa?
Or should I just scrap the DataOuputStream altogether and write the int's bytes out myself?
I'm going to test it both ways, but in the meantime, and just in case the tests are not definitive, I'm wondering if anybody here can tell me what I should expect to see.
I think I've been staring at this stuff for a bit too long and am second-guessing myself to death here no matter which way I look at it. So thanks in advance for any nudge you can give me back toward sanity.
Edited by: jverd on Feb 16, 2012 3:59 PM

EJP wrote:
So, what's the point of the basic OutputStream not being buffered then?I guess the idea was that if you want buffering you say so,Ok.
I think you'll find that every significant class that extends OutputStream (specifically FileOutputStream and SocketOutputStream) overrides write(byte[], int, int) to do an atomic write to the OS, so it isn't really such an issue except in the case of DataOutputStream (and not ObjectOutputStream, see above).Okay, so, in this case, I've got a DataOutputStream wrapped around a SocketOutputStream. It's not an issue for SOS, but it is for the wrapping DOS. Yes?
So to overcome the DOS doing a bunch of piddly 1-byte writes to the SOS, which in turn could result in a bunch of piddly 1-byte writes to the network, which I don't want, I inject a BOS between them. Yes?
Thanks for the help. I can't believe after all these years I never got these details sorted out. I guess it never came up quite this way before.

Similar Messages

  • Efficiency Question - Cutting Clips

    Efficiency Question - Cutting Clips.
    So I was wondering if there is a better way to cut my clips that I am not using. Basically I often have large long clips of raw footage that I cut down to the usable segments. Each raw file may be over an hour long and have 100s of small segments of live commentary, often I find I am cutting out slightly to long pauses in the talking and other stuff before I have a clip ready to send to the main edit.
    Anyway, often I am zoomed will in so I can edit, and I press C, make a cut.. then make another a bit further up, press V, click on the segment I just cut out.. press delete and then click on and move the rest of the raw clip to the left to bump up where I made the first cut, often needing to zoom well out and then back in again to continue editing.
    Is there a better way to do this? So I do not need to zoom in and out all the time... is there a way to delete a chunk of video form the sequence and have the clip automatically "close the gap" for me?
    --Thanks

    I would take the Source Clip into the Source Monitor.
    Mark an In Point  ("I")  where the good content starts...and an Out Point ("O")  where the good content stops.
    Hit "," to Insert it to the Sequence.
    Back to Source Monitor and repeat for the next section of good content in the same Source Clip..
    No gaps . Done
    Then ..if necessary...I would play thru  the Sequence and do Trim Edits at the editpoints.
    Many different ways to "skin the cat" at Trim stage.
    Alternatively in the first part:
    I would take the Source Clip into the Source Monitor.
    Mark an In Point ("I") where the good content starts...and an Out Point ("O") where the good content stops.
    CTRL-Drag to the Program Monitor.

  • Efficiency Question: Simple Java DC vs Used WD Component

    Hello guys,
    The scenario is - I want to call a function that returns a FileInputStream object so I can process it on my WD view. I can think of two approaches - one is to simply write a simple Java DC that does so and just use it as a used DC so I can call the functionality from there. Or create another WD DC that exposes the value (as binary) via component interface.
    I'm leaning on the simple Java DC approach - its easier to create. But I'm just curious on what would be the Pro-side (if there's any) if I use the WD Component interface approach? Is there a plus for the efficiency? (Though I doubt) Or is it just a 'best/recommended practice' approach?
    Thanks!
    Regards,
    Jan

    Hi Jan
    >one is to simply write a simple Java DC that does so and just use it as a used DC so I can call the functionality from there
    Implemented Java  API for the purpose mentioned in your question is the right way, I think. The Java API can be even located in the same WebDynpro DC as your WebDynpro components. There is not strongly necessity to put it into separate Java DC.
    >Or create another WD DC that exposes the value (as binary) via component interface
    You should not do this because in general WD components' purpose is UI, not API. Implementing WD component without any UI, but with some component interface has very-very restricted use cases. Such WD component shall only be a choice in the cases when the API is WebDynpro based and if you have to strongly use WebDynpro Runtime API in order to implement your own API.
    If your API does not require WebDynpro Runtime API invocations or anything else related to WebDynpro then your choice is simple Java API.
    >But I'm just curious on what would be the Pro-side (if there's any) if I use the WD Component interface approach? Is there a plus for the efficiency?
    No. Performance will be better in simple Java API then in WebDynpro component interface. The reason is the API will not pass thought heavy WebDynpro engine.
    BR, Siarhei

  • Hash Table efficiency question

    Hi experts,
    In my program, I want to read in a lot of string and store the occurance of each string. I found that hash table is the best and most efficient option, but the problem is that, hash table only store one item.
    So, I either have to:
    1) store an array object into each hash table entries. ie String[String][Occurance]
    2) create two hash table based on the hash code of the string.
    For 2) I am planning to store all distinct String into one hashtable using the string as the hashcode, then create another hashtable to store the occurance using the String as the hashcode.
    My question is that:
    1)which implementation is more efficient? Constantly creating String array for each entry or create two hashtables?
    2) Is the second implementation possible? Would the hashcode be mapped to different cell in the hashtable even the two hashtable are using the same hashcode and the same size?
    Thank you very much for your help.
    Kevin

    I am wondering what it is you are trying to do, but I am assuming you are trying to find the number of occurrences for a particular word, and then determining which word has the highest value or the lowest value? You can retrieve the initial String value by using the keys() method of the hashtable. You can use it to traverse the entire table and compare the counts there.
    If you really wanna store another reference for that string, create a simple object
    public final class WordCount {
       * The Word being counted.
       * @since 1.1
      private String _word;
       * Count for the Number of Words.
       * @since 1.1
      private int _count;
       * Creates a new instance of the Word Count Object.
       * @param word The Word being counted.
       * @since 1.1
      public WordCount(final String word) {
        super();
        _word = word;
        _count = 0;
       * Call this method to increment the Count for the Word.
       * @since 1.1
      public void increment() {
        _count++;
       * Retrieves the word being counted.
       * @return Word being counted.
       * @since 1.1
      public String getWord() {
        return _word;
       * Return the Count for the Word.
       * @return Non-negative count for the Word.
       * @since 1.1
      public int getCount() {
        return _count;
    }Then your method can be as follows
    * Counts the Number of Occurrences of Words within the String
    * @param someString The String to be counted for
    * @param pattern Pattern to be used to split the String
    * @since 1.1
    public static final WordCount[] countWords(final String someString, final String pattern) {
      StringTokenizer st = new StringTokenizer(someString, pattern);
      HashMap wordCountMap = new HashMap();
      while (st.hasMoreTokens()) {
        String token = st.nextToken();
        if (wordCountMap.containsKey(token)) {
          ((WordCount) wordCountMap.get(token)).increment();
        } else {
          WordCount count = new WordCount(token);
          count.increment();
          wordCountMap.put(token, count);
      Collection values = wordCountMap.values();
      return (WordCount[]) values.toArray(new WordCount[values.size()]);
    }Now you can create your own comparator classes to sort the entire array of Word Count Objects. I hope that helps
    Regards
    Jega

  • ABAP efficiency question

    Hi
    I have an internal table of the type STRING which may contain thousands of records and I am trying to get to lines which starts with a set of characters. There may be a few lines starting with that sequence and it is possible to do what I have shown below, however, is there a more efficient way to do this?
    Ideally what I would like to do is to find the lines or the index (SY-TABIX) using LOOP AT.......WHERE....My current way of doing it is not the best. Any ideas?
    DATA t_spooltext TYPE TABLE OF string. "contains thousands of lines
    DATA l_text(200) TYPE c.
    DATA l_index     TYPE i.
    LOOP AT t_spooltext INTO DATA(l_current_line).
      CONDENSE l_current_line.
      l_text = l_current_line.
      IF l_text+0(5) EQ 'H046A'.
        l_index = sy-tabix.
        ELSE
            CONTINUE.
      ENDIF.
    ENDLOOP.

    Sharath,
    Fixing what you posted, I add the sample code below:
       REPORT  z_test.
    DATA: t_spooltext TYPE TABLE OF string,
          results_tab TYPE TABLE OF match_result.
    DO 10 TIMES.
      APPEND 'H046A' TO t_spooltext.
    ENDDO.
    DO 3 TIMES.
      APPEND 'H046B' TO t_spooltext.
    ENDDO.
    FIND ALL OCCURRENCES OF 'H046A'
    IN TABLE t_spooltext
    IN CHARACTER MODE
    RESULTS results_tab.
    BREAK-POINT.
    Archana, in my point of view the user Sharath are correctly, only thing you have to watch is the form that is set to result table, as I showed above

  • Catalog efficiency question in Lightroom 3.6

    I currently have one catalog with over 22,000 photos and numerous collections in it. I recently heard about creating separate "catalogs" to better LR3's efficiency and to cut down the clutter so that I'm just working on one catalog at a time. Does anyone know the best way to go about this so as not to ruin all of my collections I have created over the past year?

    Don't do it is the answer. For most uses one catalog is the best solution.

  • Small efficiency question

    Does using braces for containing if's and for's etc affect the efficiency or size of compiled binary code?
    e.g.
    Does this make a difference:
    for( int i=0; i<N; i++ ) {
    b += f;
    As opposed to:
    for( int i=0; i<N; i++ )
    b += f;

    Actually you will get a speed increase by a factor of
    10 to 15 if you manage to write your application on
    only one line.
    :)Example 1:
    public class Test {
      public static void main(String[] args) {
        System.out.println("WTF?");
    }vs Example 2:
    public class Test{public static void main(String[] args){System.out.println("WTF?");}}So far my performance tests have proved inconclusive, but I'll be sure to write all my code like example 2 from now on : )

  • Program efficiency question

    Hello all, I was just wondering about the efficiency of some programming practices. I have a program I am working on with about 20 different files. One of the files contains all of my constants ("Constants.java")... I am wondering if it is a bad practice to just call all of the variables statically i.e.
    System.out.println(Constants.menu);
    or would it be more efficient for the classes that use Constants to implement Constants?? I believe in that case I would be able to just use:
    System.out.println(menu);
    As of right now I am using the 1st method, but I wasn't anticipating the growth of the program to be so large. Any input on this subject would be greatly appreciated. Thanks,
    dub

    or would it be more efficient for the classes that
    use Constants to implement Constants?? No.
    Using interfaces for constants is an antipattern.
    Don't dwell on these micro "efficiency" issues. Write code that's simple and easy to understand. Worry about performance in broader terms--e.g., prefer an O(N) operation to an O(N^2) one. Only diddle with those minutuae if you've determined that they're actually causing problems and the change you make will create a significant improvement.

  • Efficiency Question

    Which is more efficient: TOTEXT (field1, "MM/dd/yyyy") or use the Date tab in Format editor?  Or is it just developer's preferences?  Thanks.

    Date tab is more efficient because now crystal doesn't have to process a formula.  By using the date tab, crystal is doing nothing more than changing how it is dispalyed instead of translating the data.

  • DataGrid sort efficiency questions

    Hi,
    I guess I have two specific questions:
    1. Is sorting a DataGrid faster/slower/same by applying a
    sortCompareFunction to a specific column vs. applying a Sort object
    directly to the underlying dataprovider?
    2. It says in the following link that if you use a
    labelFunction on a column, you must also use a sortCompareFunction:
    dataGridColumn.sortCompareFunction
    ASDOC
    Is this really true - anyone know why?
    Thanks!
    -Noah

    Alexander,
    In Flex 3 sorting is controlled by the collections rather than the controls. This provides greater flexibility overall despite making it hard to adjust to. To get or set a sort on the DataGrid in Flex 3, use the sort property of its dataProvider:
    ListCollectionView(dataGrid.dataProvider).sort
    You can both read and write to the sort property. When you write to it, you have to call refresh() after for it to apply. Refer to the documentation on the ListCollectionView class for how to properly get and set its sort property.
    Thanks,
    Philip

  • New user Union efficiency question.

    I have feeling I read this some where but can no longer seem to find any information on the following:
    Which is more efficent to the following with Physical tables A and B
    SELECT * FROM (A union B) WHERE ID < 97 AND ID > 103
    or
    SELECT * FROM A WHERE ID < 97 AND ID > 103 UNION SELECT * FROM B WHERE ID < 97 AND ID > 103.
    And more to the point how would I test / profile this ?
    Thanks
    Mark

    Silly me it was a threoretical question in as much as the code I'm trying to maintain is a little more complex and the records in both tables whilst being the same do not have contiguous ID values.
    I found an article on materialized views at http://www.akadia.com/services/ora_materialized_views.html and used set autotrace on and timing on and found that after creating two copies of the same table both gave the same performance. ( with corrected Id values of course ;-))
    Thanks ever so much and Regards
    Mark.

  • ConcurrentHashMap.putIfAbsent efficiency question

    Hi,
    I have a question for the putIfAbsent method of ConcurrentHashMap. according to API, this is atomic. so just consider the following two segments of code:
    ConcurrentHashMap<Key, Value> map;
    ReentrantLock lock;
    1.
    Object obj = new Object();
    Object oldObj = map.putIfAbsent(key, obj);
    if(oldObj!=null) obj = oldObj;
    2.
    lock.lock();
    try{
    Object obj = map.get(key);
    if(obj==null){
    obj = new Object();
    map.put(key, obj);
    } finally {
    lock.unlock();
    I am new to the concurrent package and thus don't know the performance issues. For approach 1 I think the potential problem is Object creation everytime no matter the Object exists in the map or not. Would anyone tell me which will have better performance when the map contains lots of objects and the map insert rate is very high?
    Thanks,
    Benny

    Using Locks is hard and errorprone, use ConcurrentHashMap and other collections since inventing your own locking mechnism would be difficult.
    If you manage to implement your own fast locking mechnism for hashmaps you want to publish it in a Academic Paper so others can implement it too. Like that ConcurrentLinkedQueue that is based on a paper from 1996 http://www.cs.rochester.edu/u/michael/PODC96.html.

  • How do I request help for an Acrobat search efficiency question?

    I have had a search time degradation of 60x-70x when I switch to Acrobat X or XI (went from 14 seconds on v9.5 to 841 seconds with X or 991 seconds seconds with XI).  I am trying to find out where I can ask about this to see what I can do to improve the speed of my searches.
    Is this forum a good place to ask?  My prior posting was at:
       http://forums.adobe.com/message/5338121#5338121
    Thanks.

    The PDF files I search are fairly large.  I was told they are "text under image".  They represent the pages of an organization's bimonthly journal over the course of 80 years.  There are 16 files, averaging about 800 pages per file -- totalling around 600MB.  The ability to search across all those pages in 14 seconds rather than 1000 seconds is greatly desired.
    What kind of additional information would be appropriate and helpful?  Should I repost the details I had included under the other forum?  Are there other tests I should try?
    Am I the only one who has had this kind of issue?  I searched to find similar discussions or articles but had found none.
    Is this the appropriate forum in which to follow up as a discussion?
    BTW --  Best regards, and thanks for your feedback.

  • Noobish Openbox Questions

    How would I run a script on startup? I know how to run an app, but not a script. Say scpript.sh
    Where should I edit to disable tap to click, as its messing with my macbook magic touchpad.
    Last edited by duke11235 (2010-08-25 00:17:57)

    To autostart your script, edit the autostart.sh file from ~/.config/openbox.
    Place this in the file:
    ~/path/to/script.sh &
    Remeber to put "&" at the end, or the next command(s) won't start.
    Have fun with Openbox.

  • Why should I use the OpenDocument file format?

    Forgive the noobish sounding question, because I'm definitely not a linux newbie anymore. The current xkcd (http://www.xkcd.com/743) got me thinking. I never had a problem with .doc files before, because everything can read them. And I'd never used .odt files before because I only recently discovered abiword-plugins lets me read .odt files in Abiword.
    So, I'd like you to please convince me why I should use .odt files over .doc files. Thank you.

    drcouzelis wrote:
    I wonder if it would be worth it to teach people how to use LaTeX. I certainly don't think it's more complicated than writing a Word document in all cases. I can't believe how much time my coworkers spend try to "format" many of the 50+ page documents we work with. So often I hear problems like "This page break is wrong", "The index links are all messed up", "How do I get rid of this space?", and similar. Some of the time the answer is "We'll just leave it" or "I'll just re-write it". I thought all of those big fancy buttons on the top of the window were supposed to make writing a Word document easy? /rant
    Say, is there an application that allows a person to right-click on a TEX file and "Open (as PDF)" and "Edit (as TEXT)", For any OS? You know, kind of like a JIT compiler.
    ...and is this too off-topic?
    Well, I could share my experience here.
    1. LaTeX is probably similar to Perl or Vim in terms of the learning curve. I mean, it's more "learn as you work" thing: LaTeX relies heavily on it CTAN repository and there are lots of different ways to do the same thing. Which is why all the guides are more like cookbooks with recipes how to perform different kind of tasks, not a 101 tutorial.
    2. LaTeX is more oriented towards large documents, rather books than articles. Which means, one doesn't really need all of the features that LaTeX has to markup a document less than 50 pages. Most of the guides teach you how to work with books, while most of the users need to work with smaller texts. It's not a real problem for somebody who uses LaTeX for publishing his books to use it for smaller texts, but in other cases it's a bit challenging.
    Whenever you grab a LaTeX guide, you can strip it off all the advanced topics and you'll find out that merely one or two chapters are needed for most WYSIWYG converts: document structure (the essential packages, etc), beautifiers (boldface, italic, underlining, etc), paragraph formatting (alignments, columns, etc) headers/titles, tables, images embedding and footnotes. All of this can be described in 50 pages at most, and that would be totally comprehensive.
    So basically, one just needs a guide to LaTeX for word processing. Learning LaTeX for that purposes using publishing-oriented guides is really time consuming.
    Perhaps, there is even some kind of a special macro for word processing, that has less features, but makes them easier to memorize and use - I don't know.
    Actually, Pandoc's user guide could be a nice starting point, since pandoc has exactly the needed feature set. You should just expand it with some page properties (interlinear interval, page margins, etc), a review of the available tools for LaTeX (aucTeX, vim-latex, LyX, Kile, gummi, may be some popular extensions to Geany, Gedit, Kate), some popular Web resources (package reviews, tips-and-tricks wikis, etc) and some further reading.

Maybe you are looking for

  • Windows 8.1 error when printing photsmart B110 all in one series

    When going to print a document of more than one page the system goes into print mode but after a short delay the windows error screen appears saying there was an error to the printer. Howvever the printer some times prints the whole document or only

  • Bizarre Error

    Here's what I'm trying to do...  I have a List whose source is an ArrayCollection populated with objects, and the list displays one of the object's string members for the label...  Then, I have a DataGrid (one column) that will accept the objects fro

  • Grab doesn't take screen shot of selected area.

    Using Lion, Grab (screen shot) doesn't work like it used to. I select an area, Cmd-Shift-4, release mouse button. It "grabs" a shot of a different area.

  • Icons dissapear from desktop

    I have a HP EliteDesk 800 gi sff computer that runs win7 64 bit. Seems like about once a week somtimes more often I will lose desktop icons the seem to be only network shortcuts but they will dissaper from my desktop. Any one have an idea on how to f

  • Sync AUDIO to VIDEO in FCPX with timecode only  (no scratch audio)

    We shot a film on the RED.  We will be editing the film in Apple ProRes. The audio was recorded separately.  And we have no camera audio to use as scratch to sync audio waveforms with AutoSync. I am looking for a solution to batch sync my project usi