Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8243131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:24:34+00:00 2026-06-07T21:24:34+00:00

Basically, my situation is this: Server streams data from the client connection to a

  • 0

Basically, my situation is this:

  1. Server streams data from the client connection to a ByteBuffer object called inQueue. This contains whatever the most recent stream of data is
  2. Server must process the data in each of these streams and expect a packet of data in a specific format
  3. The payload of data is to be read into a byte[] object then processed separately

Now my question boils down to this: is copying the remaining buffer data (the payload) to a byte[] array bad for performance?

Here’s what it would look like:

// pretend we're reading the packet ID and length
// int len = LENGTH OF PACKET PAYLOAD

/* 
 * Mark the starting position of the packet's payload.
 */
int pos = inQueue.position();

byte[] payload = new byte[len];
inQueue.get(payload);

// Process the packet's payload here

/*
 * Set the inQueue buffer to the length added to the previous position
 * so as to move onto the next packet to process.
 */
inQueue.position(pos + len);

As you can see, I’m essentially doing this:

  1. Mark the position of the complete buffer as it were just before the payload
  2. Copy the contents of inQueue as far as the payload goes to a separate byte[] object
  3. Set the complete buffer’s position to after the payload we just read so we can read more packets

My concern is that, in doing this, I’m wasting memory by copying the buffer. Keep in mind the packets used will never exceed 500 bytes and are often under 100 bytes.

Is my concern valid, or am I being performance-paranoid? :p

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:24:35+00:00Added an answer on June 7, 2026 at 9:24 pm

    Not only is this unnecessary but, to answer your question, no you won’t notice a performance change even when scaling up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am confounded with a strange issue. Basically the situation is like this. I
So, this is somewhat of a strange situation. I'm hosting a development server for
When will I normally need different ports for client-server communication? (This question is for
I've got a server script receiving an uploaded file from Javascript. Client-side, using a
I'm basically stuck in a situation where I need a bunch of div's with
Basically from C++ FAQ I learned that: A virtual function allows derived classes to
Basically I have a large set of data in excel, and I was wondering
I have a project coming up for client who is basically happy with how
I am really frustrated by this whole situation, and here is why: I inherited
I have a slightly unusual situation where I'm needing to maintain CLIENT tcp connections

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.