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 7045915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:35:18+00:00 2026-05-28T02:35:18+00:00

Which is preferable? Assume this code before each: byte[] data = Encoding.ASCII.GetBytes(Test Packet Message);

  • 0

Which is preferable?

Assume this code before each:

byte[] data = Encoding.ASCII.GetBytes("Test Packet Message");
byte[] header = BitConverter.GetBytes(data.Length);

A:

clientStream.Write(header, 0, header.Length);
clientStream.Write(data, 0, data.Length);

B:

byte[] bytes = new byte[header.Length + data.Length];

Buffer.BlockCopy(header, 0, bytes, 0, header.Length);
Buffer.BlockCopy(data, 0, bytes, header.Length, data.Length);

clientStream.Write(bytes, 0, bytes.Length);

A has the benefit of not having to copy the bytes from one array to another so it is easier on the CPU (both clients and servers have to send and receive data so the A approach may be faster if sending a lot of data.

B has the benefit of only sending one packet. People talk of the overhead of sending single small packets. Also, Nagle’s algorithm may come in to play with A as evidenced from this post.

What would be nice was if there was a way too accomplish A without having to copy all the bytes from the header and data arrays to the bytes array but I’m not sure if that is possible.. Seems like there is a way to optimize it/make it more efficient but I’m not sure.

  • 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-05-28T02:35:18+00:00Added an answer on May 28, 2026 at 2:35 am

    I would expect that the following method that accepts multiple buffers would achieve what you are looking for. However, I would want to test it to determine exactly what was being sent in terms of packets.

    //Sends the set of buffers in the list to a connected Socket, using the specified SocketFlags.
    Socket.Send Method (IList<ArraySegment<Byte>>, SocketFlags)
    

    See the following post:

    UDP – Can I send two datagram parts, and make the receiving end combine them into one?

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

Sidebar

Related Questions

In which cases storing data as XML is preferable to RDBMS and why? Can
Which is preferable Sample.this.display() or this.display()? class Sample{ void display(){ System.out.println(display() called); } void
Which one is preferable or more clear? public int FrozenRegionWidth { get; set; }
VBA is a programming language so I'll assume this question is ok on SO.
I have a text like Previously which looks English but has a non-ASCII characters
Which is the preferable method of populating a <select> dropdown through one of jQuery's
This question may be extremely naive, in which case, I apologize. I'm trying to
Which is preferable? <%= raw @item.description %> or <%= @item.description.html_safe %>
Is there a tool (preferably free) which will translate Oracle's PL/SQL stored procedure language
I'm looking for something (preferably a Firefox extension) which will allow me to see

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.